Skip to content

Commit 2bcd8e7

Browse files
authored
Update SSE on file/dir changes (codesandbox#3342)
1 parent 329dc37 commit 2bcd8e7

File tree

1 file changed

+19
-2
lines changed
  • packages/app/src/app/overmind/namespaces/files

1 file changed

+19
-2
lines changed

packages/app/src/app/overmind/namespaces/files/actions.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const moduleRenamed: AsyncAction<{
6262
if (state.live.isCurrentEditor) {
6363
effects.live.sendModuleUpdate(module);
6464
}
65+
effects.executor.updateFiles(state.editor.currentSandbox);
6566
} catch (error) {
6667
module.title = oldTitle;
6768
state.editor.modulesByPath = effects.vscode.sandboxFsSync.create(sandbox);
@@ -123,6 +124,7 @@ export const directoryCreated: AsyncAction<{
123124
});
124125

125126
effects.live.sendDirectoryCreated(directory);
127+
effects.executor.updateFiles(state.editor.currentSandbox);
126128
} catch (error) {
127129
const directoryIndex = state.editor.currentSandbox.directories.findIndex(
128130
directoryItem => directoryItem.shortid === optimisticDirectory.shortid
@@ -176,6 +178,7 @@ export const moduleMovedToDirectory: AsyncAction<{
176178
directoryShortid
177179
);
178180
effects.live.sendModuleUpdate(module);
181+
effects.executor.updateFiles(state.editor.currentSandbox);
179182
} catch (error) {
180183
module.directoryShortid = currentDirectoryShortid;
181184
module.path = oldPath;
@@ -222,6 +225,7 @@ export const directoryMovedToDirectory: AsyncAction<{
222225
directoryShortid
223226
);
224227
effects.live.sendDirectoryUpdate(directoryToMove);
228+
effects.executor.updateFiles(state.editor.currentSandbox);
225229
} catch (error) {
226230
directoryToMove.directoryShortid = shortid;
227231
directoryToMove.path = oldPath;
@@ -283,6 +287,7 @@ export const directoryDeleted: AsyncAction<{
283287
try {
284288
await effects.api.deleteDirectory(sandbox.id, directoryShortid);
285289
effects.live.sendDirectoryDeleted(directoryShortid);
290+
effects.executor.updateFiles(state.editor.currentSandbox);
286291
} catch (error) {
287292
sandbox.directories.push(removedDirectory);
288293

@@ -337,6 +342,8 @@ export const directoryRenamed: AsyncAction<{
337342
if (state.live.isCurrentEditor) {
338343
effects.live.sendDirectoryUpdate(directory);
339344
}
345+
346+
effects.executor.updateFiles(state.editor.currentSandbox);
340347
} catch (error) {
341348
directory.title = oldTitle;
342349
state.editor.modulesByPath = effects.vscode.sandboxFsSync.create(sandbox);
@@ -374,14 +381,16 @@ export const gotUploadedFiles: AsyncAction<string> = async (
374381
export const addedFileToSandbox: AsyncAction<{
375382
url: string;
376383
name: string;
377-
}> = withOwnedSandbox(async ({ actions }, { name, url }) => {
384+
}> = withOwnedSandbox(async ({ actions, effects, state }, { name, url }) => {
378385
actions.internal.closeModals(false);
379386
await actions.files.moduleCreated({
380387
title: name,
381388
directoryShortid: null,
382389
code: url,
383390
isBinary: true,
384391
});
392+
393+
effects.executor.updateFiles(state.editor.currentSandbox);
385394
});
386395

387396
export const deletedUploadedFile: AsyncAction<{
@@ -425,6 +434,8 @@ export const filesUploaded: AsyncAction<{
425434
directories,
426435
directoryShortid,
427436
});
437+
438+
effects.executor.updateFiles(state.editor.currentSandbox);
428439
} catch (error) {
429440
if (error.message.indexOf('413') !== -1) {
430441
actions.internal.handleError({
@@ -494,6 +505,8 @@ export const massCreateModules: AsyncAction<{
494505
if (cbID) {
495506
effects.vscode.callCallback(cbID);
496507
}
508+
509+
effects.executor.updateFiles(state.editor.currentSandbox);
497510
} catch (error) {
498511
if (cbID) {
499512
effects.vscode.callCallbackError(cbID, error.message);
@@ -582,6 +595,7 @@ export const moduleCreated: AsyncAction<{
582595
if (state.live.isCurrentEditor) {
583596
effects.live.sendModuleCreated(module);
584597
}
598+
effects.executor.updateFiles(state.editor.currentSandbox);
585599
} catch (error) {
586600
sandbox.modules.splice(sandbox.modules.indexOf(module), 1);
587601
actions.editor.internal.setCurrentModule(state.editor.mainModule);
@@ -625,6 +639,7 @@ export const moduleDeleted: AsyncAction<{
625639
if (state.live.isCurrentEditor) {
626640
effects.live.sendModuleDeleted(moduleShortid);
627641
}
642+
effects.executor.updateFiles(state.editor.currentSandbox);
628643
} catch (error) {
629644
sandbox.modules.push(removedModule);
630645
state.editor.modulesByPath = effects.vscode.sandboxFsSync.create(sandbox);
@@ -636,7 +651,7 @@ export const moduleDeleted: AsyncAction<{
636651
export const createModulesByPath: AsyncAction<{
637652
cbID: string;
638653
files: INormalizedModules;
639-
}> = async ({ state, actions }, { files, cbID }) => {
654+
}> = async ({ state, effects, actions }, { files, cbID }) => {
640655
const sandbox = state.editor.currentSandbox;
641656

642657
const { modules, directories } = denormalize(files, sandbox.directories);
@@ -647,6 +662,8 @@ export const createModulesByPath: AsyncAction<{
647662
directoryShortid: null,
648663
cbID,
649664
});
665+
666+
effects.executor.updateFiles(state.editor.currentSandbox);
650667
};
651668

652669
export const syncSandbox: AsyncAction<any[]> = async (

0 commit comments

Comments
 (0)