Skip to content

Commit 3099d2a

Browse files
authored
Disallow a fork when a fork is in progress (codesandbox#2834)
* Disallow a fork when a fork is in progress * Add cancel scenario for withOwnedSandbox * Cleanup
1 parent 299c273 commit 3099d2a

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

packages/app/src/app/overmind/factories.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,16 @@ export const withLoadApp = <T>(
6666
};
6767

6868
export const withOwnedSandbox = <T>(
69-
continueAction: AsyncAction<T>
69+
continueAction: AsyncAction<T>,
70+
cancelAction: AsyncAction<T> = () => Promise.resolve()
7071
): AsyncAction<T> => async (context, payload) => {
7172
const { state, actions } = context;
7273

7374
if (!state.editor.currentSandbox.owned) {
75+
if (state.editor.isForkingSandbox) {
76+
return cancelAction(context, payload);
77+
}
78+
7479
await actions.editor.internal.forkSandbox({
7580
sandboxId: state.editor.currentId,
7681
});
@@ -87,11 +92,10 @@ export const withOwnedSandbox = <T>(
8792
} else if (modalResponse === 'unfreeze') {
8893
state.editor.sessionFrozen = false;
8994
} else if (modalResponse === 'cancel') {
90-
return;
95+
return cancelAction(context, payload);
9196
}
9297
}
9398

94-
// eslint-disable-next-line consistent-return
9599
return continueAction(context, payload);
96100
};
97101

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,18 @@ export const codeSaved: AsyncAction<{
152152
code: string;
153153
moduleShortid: string;
154154
cbID: string;
155-
}> = withOwnedSandbox(async ({ actions }, { code, moduleShortid, cbID }) => {
156-
actions.editor.internal.saveCode({
157-
code,
158-
moduleShortid,
159-
cbID,
160-
});
161-
});
155+
}> = withOwnedSandbox(
156+
async ({ actions }, { code, moduleShortid, cbID }) => {
157+
actions.editor.internal.saveCode({
158+
code,
159+
moduleShortid,
160+
cbID,
161+
});
162+
},
163+
async ({ effects }, { cbID }) => {
164+
effects.vscode.callCallbackError(cbID);
165+
}
166+
);
162167

163168
export const codeChanged: Action<{
164169
code: string;

packages/app/src/app/overmind/namespaces/editor/internalActions.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,15 @@ export const saveCode: AsyncAction<{
166166
effects.notificationToast.warning(error.message);
167167

168168
if (cbID) {
169-
effects.vscode.callCallbackError(cbID);
169+
effects.vscode.callCallbackError(cbID, error.message);
170170
}
171171
}
172172
};
173173

174-
export const updateCurrentTemplate: Action = ({ state, effects }) => {
174+
export const updateCurrentTemplate: AsyncAction = async ({
175+
state,
176+
effects,
177+
}) => {
175178
try {
176179
const currentTemplate = state.editor.currentSandbox.template;
177180
const templateDefinition = getTemplateDefinition(currentTemplate);
@@ -201,7 +204,7 @@ export const updateCurrentTemplate: Action = ({ state, effects }) => {
201204
getTemplateDefinition(newTemplate).isServer
202205
) {
203206
state.editor.currentSandbox.template = newTemplate;
204-
effects.api.saveTemplate(state.editor.currentId, newTemplate);
207+
await effects.api.saveTemplate(state.editor.currentId, newTemplate);
205208
}
206209
}
207210
} catch (e) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ export const massCreateModules: AsyncAction<{
308308
cbID?: string;
309309
}> = withOwnedSandbox(
310310
async (
311-
{ state, effects, actions },
311+
{ state, effects },
312312
{ modules, directories, directoryShortid, cbID }
313313
) => {
314314
const sandboxId = state.editor.currentId;
@@ -337,7 +337,7 @@ export const massCreateModules: AsyncAction<{
337337
}
338338
} catch (error) {
339339
if (cbID) {
340-
effects.vscode.callCallbackError(cbID);
340+
effects.vscode.callCallbackError(cbID, error.message);
341341
}
342342
effects.notificationToast.error('Unable to create new files');
343343
}

0 commit comments

Comments
 (0)