@@ -17,6 +17,7 @@ import {
1717import { clearCorrectionsFromAction } from 'app/utils/corrections' ;
1818import { json } from 'overmind' ;
1919
20+ import getTemplate from '@codesandbox/common/lib/templates' ;
2021import * as internalActions from './internalActions' ;
2122
2223export const internal = internalActions ;
@@ -43,6 +44,8 @@ export const addNpmDependency: AsyncAction<{
4344 version : newVersion ,
4445 isDev : Boolean ( isDev ) ,
4546 } ) ;
47+
48+ actions . editor . internal . updatePreviewCode ( ) ;
4649 }
4750) ;
4851
@@ -61,6 +64,8 @@ export const npmDependencyRemoved: AsyncAction<{
6164 moduleShortid : state . editor . currentPackageJSON . shortid ,
6265 cbID : null ,
6366 } ) ;
67+
68+ actions . editor . internal . updatePreviewCode ( ) ;
6469} ) ;
6570
6671export const sandboxChanged : AsyncAction < { id : string } > = withLoadApp < {
@@ -233,6 +238,12 @@ export const codeChanged: Action<{
233238 module,
234239 code,
235240 } ) ;
241+
242+ const { isServer } = getTemplate ( state . editor . currentSandbox . template ) ;
243+
244+ if ( ! isServer && state . preferences . settings . livePreviewEnabled ) {
245+ actions . editor . internal . updatePreviewCode ( ) ;
246+ }
236247} ;
237248
238249export const saveClicked : AsyncAction = withOwnedSandbox (
@@ -256,6 +267,8 @@ export const saveClicked: AsyncAction = withOwnedSandbox(
256267 ) {
257268 actions . git . internal . fetchGitChanges ( ) ;
258269 }
270+
271+ effects . preview . executeCodeImmediately ( ) ;
259272 } catch ( error ) {
260273 // Put back any unsaved modules taking into account that you
261274 // might have changed some modules waiting for saving
@@ -367,6 +380,10 @@ export const moduleSelected: Action<{
367380 }
368381
369382 effects . live . sendUserCurrentModule ( module . shortid ) ;
383+
384+ if ( ! state . editor . isInProjectView ) {
385+ actions . editor . internal . updatePreviewCode ( ) ;
386+ }
370387 }
371388 } catch ( error ) {
372389 // Do nothing, it is most likely VSCode selecting a file
@@ -453,8 +470,9 @@ export const toggleStatusBar: Action = ({ state }) => {
453470 state . editor . statusBar = ! state . editor . statusBar ;
454471} ;
455472
456- export const projectViewToggled : Action = ( { state } ) => {
473+ export const projectViewToggled : Action = ( { state, actions } ) => {
457474 state . editor . isInProjectView = ! state . editor . isInProjectView ;
475+ actions . editor . internal . updatePreviewCode ( ) ;
458476} ;
459477
460478export const frozenUpdated : AsyncAction < { frozen : boolean } > = async (
@@ -710,7 +728,6 @@ export const previewActionReceived: Action<{
710728 actions . editor . addNpmDependency ( {
711729 name,
712730 } ) ;
713- actions . forceRender ( ) ;
714731 break ;
715732 }
716733 }
@@ -719,37 +736,35 @@ export const previewActionReceived: Action<{
719736export const renameModule : AsyncAction < {
720737 title : string ;
721738 moduleShortid : string ;
722- } > = withOwnedSandbox (
723- async ( { state, effects, actions } , { title, moduleShortid } ) => {
724- const sandbox = state . editor . currentSandbox ;
725- const module = sandbox . modules . find (
726- moduleItem => moduleItem . shortid === moduleShortid
727- ) ;
739+ } > = withOwnedSandbox ( async ( { state, effects } , { title, moduleShortid } ) => {
740+ const sandbox = state . editor . currentSandbox ;
741+ const module = sandbox . modules . find (
742+ moduleItem => moduleItem . shortid === moduleShortid
743+ ) ;
728744
729- if ( ! module ) {
730- return ;
731- }
745+ if ( ! module ) {
746+ return ;
747+ }
732748
733- const oldTitle = module . title ;
749+ const oldTitle = module . title ;
734750
735- module . title = title ;
751+ module . title = title ;
736752
737- try {
738- await effects . api . saveModuleTitle (
739- state . editor . currentId ,
740- moduleShortid ,
741- title
742- ) ;
753+ try {
754+ await effects . api . saveModuleTitle (
755+ state . editor . currentId ,
756+ moduleShortid ,
757+ title
758+ ) ;
743759
744- if ( state . live . isCurrentEditor ) {
745- effects . live . sendModuleUpdate ( module ) ;
746- }
747- } catch ( error ) {
748- module . title = oldTitle ;
749- effects . notificationToast . error ( 'Could not rename file' ) ;
760+ if ( state . live . isCurrentEditor ) {
761+ effects . live . sendModuleUpdate ( module ) ;
750762 }
763+ } catch ( error ) {
764+ module . title = oldTitle ;
765+ effects . notificationToast . error ( 'Could not rename file' ) ;
751766 }
752- ) ;
767+ } ) ;
753768
754769export const onDevToolsTabAdded : Action < {
755770 tab : any ;
0 commit comments