Skip to content

Commit c8cead6

Browse files
use sandbox.id instead of currentId
1 parent cfcd54b commit c8cead6

File tree

11 files changed

+37
-55
lines changed

11 files changed

+37
-55
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,8 @@ export const refetchSandboxInfo: AsyncAction = async ({
216216
actions,
217217
}) => {
218218
if (state.editor.currentId) {
219-
const id = state.editor.currentId;
220219
const sandbox = state.editor.currentSandbox;
221-
const updatedSandbox = await effects.api.getSandbox(id);
220+
const updatedSandbox = await effects.api.getSandbox(sandbox.id);
222221

223222
sandbox.collection = updatedSandbox.collection;
224223
sandbox.owned = updatedSandbox.owned;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const withOwnedSandbox = <T>(
8383
}
8484

8585
await actions.editor.internal.forkSandbox({
86-
sandboxId: state.editor.currentId,
86+
sandboxId: state.editor.currentSandbox.id,
8787
});
8888
} else if (
8989
state.editor.currentSandbox.isFrozen &&
@@ -93,7 +93,7 @@ export const withOwnedSandbox = <T>(
9393

9494
if (modalResponse === 'fork') {
9595
await actions.editor.internal.forkSandbox({
96-
sandboxId: state.editor.currentId,
96+
sandboxId: state.editor.currentSandbox.id,
9797
});
9898
} else if (modalResponse === 'unfreeze') {
9999
state.editor.sessionFrozen = false;

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,6 @@ export const setCurrentSandbox: AsyncAction<Sandbox> = async (
171171
{ state, effects, actions },
172172
sandbox
173173
) => {
174-
const oldSandboxId =
175-
state.editor.currentId === sandbox.id ? null : state.editor.currentId;
176-
177174
state.editor.sandboxes[sandbox.id] = sandbox;
178175
state.editor.currentId = sandbox.id;
179176

@@ -288,13 +285,6 @@ export const setCurrentSandbox: AsyncAction<Sandbox> = async (
288285
});
289286

290287
effects.executor.setupExecutor();
291-
292-
/*
293-
There seems to be a race condition here? Verify if this still happens with Overmind
294-
*/
295-
if (oldSandboxId && oldSandboxId !== state.editor.currentId) {
296-
delete state.editor.sandboxes[oldSandboxId];
297-
}
298288
};
299289

300290
export const updateCurrentSandbox: AsyncAction<Sandbox> = async (

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Action, AsyncAction } from 'app/overmind';
2+
23
import * as internalActions from './internalActions';
34

45
export const internal = internalActions;
@@ -42,10 +43,10 @@ export const deployWithNetlify: AsyncAction = async ({
4243
export const getNetlifyDeploys: AsyncAction = async ({ state, effects }) => {
4344
try {
4445
state.deployment.netlifyClaimUrl = await effects.netlify.claimSite(
45-
state.editor.currentId
46+
state.editor.currentSandbox.id
4647
);
4748
state.deployment.netlifySite = await effects.netlify.getDeployments(
48-
state.editor.currentId
49+
state.editor.currentSandbox.id
4950
);
5051
} catch (error) {
5152
state.deployment.netlifySite = null;

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
7878
newId = actions.editor.internal.ensureSandboxId(newId);
7979

8080
// This happens when we fork. This can be avoided with state first routing
81-
if (state.editor.currentId === newId) {
81+
if (state.editor.isForkingSandbox) {
8282
return;
8383
}
8484

@@ -304,7 +304,7 @@ export const forkSandboxClicked: AsyncAction = async ({
304304
}
305305

306306
await actions.editor.internal.forkSandbox({
307-
sandboxId: state.editor.currentId,
307+
sandboxId: state.editor.currentSandbox.id,
308308
});
309309
};
310310

@@ -475,7 +475,7 @@ export const frozenUpdated: AsyncAction<{ frozen: boolean }> = async (
475475
) => {
476476
state.editor.currentSandbox.isFrozen = frozen;
477477

478-
await effects.api.saveFrozen(state.editor.currentId, frozen);
478+
await effects.api.saveFrozen(state.editor.currentSandbox.id, frozen);
479479
};
480480

481481
export const quickActionsOpened: Action = ({ state }) => {
@@ -531,15 +531,15 @@ export const fetchEnvironmentVariables: AsyncAction = async ({
531531
effects,
532532
}) => {
533533
state.editor.currentSandbox.environmentVariables = await effects.api.getEnvironmentVariables(
534-
state.editor.currentId
534+
state.editor.currentSandbox.id
535535
);
536536
};
537537

538538
export const updateEnvironmentVariables: AsyncAction<
539539
EnvironmentVariable
540540
> = async ({ state, effects }, environmentVariable) => {
541541
state.editor.currentSandbox.environmentVariables = await effects.api.saveEnvironmentVariable(
542-
state.editor.currentId,
542+
state.editor.currentSandbox.id,
543543
environmentVariable
544544
);
545545

@@ -549,7 +549,7 @@ export const updateEnvironmentVariables: AsyncAction<
549549
export const deleteEnvironmentVariable: AsyncAction<{
550550
name: string;
551551
}> = async ({ state, effects }, { name }) => {
552-
const id = state.editor.currentId;
552+
const { id } = state.editor.currentSandbox;
553553

554554
state.editor.currentSandbox.environmentVariables = await effects.api.deleteEnvironmentVariable(
555555
id,
@@ -745,11 +745,7 @@ export const renameModule: AsyncAction<{
745745
module.title = title;
746746

747747
try {
748-
await effects.api.saveModuleTitle(
749-
state.editor.currentId,
750-
moduleShortid,
751-
title
752-
);
748+
await effects.api.saveModuleTitle(sandbox.id, moduleShortid, title);
753749

754750
if (state.live.isCurrentEditor) {
755751
effects.live.sendModuleUpdate(module);

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ export const updateCurrentTemplate: AsyncAction = async ({
188188
getTemplateDefinition(newTemplate).isServer
189189
) {
190190
state.editor.currentSandbox.template = newTemplate;
191-
await effects.api.saveTemplate(state.editor.currentId, newTemplate);
191+
await effects.api.saveTemplate(
192+
state.editor.currentSandbox.id,
193+
newTemplate
194+
);
192195
}
193196
}
194197
} catch (e) {
@@ -223,7 +226,6 @@ export const setModuleCode: Action<{
223226
module: Module;
224227
code: string;
225228
}> = ({ state, effects }, { module, code }) => {
226-
const { currentId } = state.editor;
227229
const { currentSandbox } = state.editor;
228230
const hasChangedModuleId = state.editor.changedModuleShortids.includes(
229231
module.shortid
@@ -253,7 +255,7 @@ export const setModuleCode: Action<{
253255

254256
// Save the code to localStorage so we can recover in case of a crash
255257
effects.moduleRecover.save(
256-
currentId,
258+
currentSandbox.id,
257259
currentSandbox.version,
258260
module,
259261
code,
@@ -309,8 +311,7 @@ export const forkSandbox: AsyncAction<{
309311
effects.preview.executeCodeImmediately(true);
310312

311313
// When not server we "piggyback" the existing Sandbox to avoid any rerenders and need
312-
// for new bundler. We do not reference the sandbox by `currentId` anywhere,
313-
// so this should be safe. The url of the preview is updated
314+
// for new bundler. Preview updates its url though
314315
} else {
315316
Object.assign(
316317
state.editor.sandboxes[state.editor.currentId],

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,7 @@ export const directoryDeleted: AsyncAction<{
225225
effects.vscode.openModule(state.editor.currentModule);
226226
actions.editor.internal.updatePreviewCode();
227227
try {
228-
await effects.api.deleteDirectory(
229-
state.editor.currentId,
230-
directoryShortid
231-
);
228+
await effects.api.deleteDirectory(sandbox.id, directoryShortid);
232229
effects.live.sendDirectoryDeleted(directoryShortid);
233230
} catch (error) {
234231
sandbox.directories.push(removedDirectory);
@@ -374,7 +371,7 @@ export const massCreateModules: AsyncAction<{
374371
{ state, actions, effects },
375372
{ modules, directories, directoryShortid, cbID }
376373
) => {
377-
const sandboxId = state.editor.currentId;
374+
const sandboxId = state.editor.currentSandbox.id;
378375

379376
try {
380377
const data = await effects.api.massCreateModules(
@@ -550,7 +547,7 @@ export const syncSandbox: AsyncAction<any[]> = async (
550547
{ state, effects },
551548
updates
552549
) => {
553-
const id = state.editor.currentId;
550+
const { id } = state.editor.currentSandbox;
554551

555552
try {
556553
const newSandbox = await effects.api.getSandbox(id);

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Action, AsyncAction } from 'app/overmind';
2+
23
import * as internalActions from './internalActions';
34

45
export const internal = internalActions;
@@ -50,7 +51,7 @@ export const gitMounted: AsyncAction = ({ actions }) =>
5051

5152
export const createCommitClicked: AsyncAction = async ({ state, effects }) => {
5253
const { git } = state;
53-
const id = state.editor.currentId;
54+
const { id } = state.editor.currentSandbox;
5455

5556
git.commit = null;
5657
git.isCommitting = true;
@@ -91,7 +92,7 @@ export const createPrClicked: AsyncAction = async ({ state, effects }) => {
9192
state.git.isCreatingPr = true;
9293
state.currentModal = 'pr';
9394

94-
const id = state.editor.currentId;
95+
const { id } = state.editor.currentSandbox;
9596
const pr = await effects.api.createGitPr(
9697
id,
9798
`${state.git.subject}${
@@ -104,9 +105,7 @@ export const createPrClicked: AsyncAction = async ({ state, effects }) => {
104105

105106
const { user } = state;
106107
const git = state.editor.currentSandbox.originalGit;
107-
const url = `https://github.com/${git.username}/${git.repo}/compare/${
108-
git.branch
109-
}...${user.username}:${pr.newBranch}?expand=1`;
108+
const url = `https://github.com/${git.username}/${git.repo}/compare/${git.branch}...${user.username}:${pr.newBranch}?expand=1`;
110109

111110
state.git.pr.prURL = url;
112111

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AsyncAction } from 'app/overmind';
22

33
export const fetchGitChanges: AsyncAction = async ({ state, effects }) => {
4-
const id = state.editor.currentId;
4+
const { id } = state.editor.currentSandbox;
55

66
state.git.isFetching = true;
77
state.git.originalGitChanges = await effects.api.getGitChanges(id);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export const externalResourceAdded: AsyncAction<{
131131
actions.editor.internal.updatePreviewCode();
132132

133133
try {
134-
await effects.api.createResource(state.editor.currentId, resource);
134+
await effects.api.createResource(state.editor.currentSandbox.id, resource);
135135
} catch (error) {
136136
externalResources.splice(externalResources.indexOf(resource), 1);
137137
effects.notificationToast.error('Could not save external resource');
@@ -149,7 +149,7 @@ export const externalResourceRemoved: AsyncAction<{
149149
actions.editor.internal.updatePreviewCode();
150150

151151
try {
152-
await effects.api.deleteResource(state.editor.currentId, resource);
152+
await effects.api.deleteResource(state.editor.currentSandbox.id, resource);
153153
} catch (error) {
154154
externalResources.splice(resourceIndex, 0, resource);
155155
effects.notificationToast.error(
@@ -172,7 +172,7 @@ export const sandboxDeleted: AsyncAction = async ({
172172
}) => {
173173
actions.modalClosed();
174174

175-
await effects.api.deleteSandbox(state.editor.currentId);
175+
await effects.api.deleteSandbox(state.editor.currentSandbox.id);
176176

177177
// Not sure if this is in use?
178178
state.workspace.showDeleteSandboxModal = false;
@@ -186,7 +186,7 @@ export const sandboxPrivacyChanged: AsyncAction<{
186186
}> = async ({ state, effects, actions }, { privacy }) => {
187187
const oldPrivacy = state.editor.currentSandbox.privacy;
188188
const sandbox = await effects.api.updatePrivacy(
189-
state.editor.currentId,
189+
state.editor.currentSandbox.id,
190190
privacy
191191
);
192192
state.editor.currentSandbox.previewSecret = sandbox.previewSecret;
@@ -225,7 +225,7 @@ export const deleteTemplate: AsyncAction = async ({
225225
effects,
226226
}) => {
227227
effects.analytics.track('Template - Removed', { source: 'editor' });
228-
const sandboxId = state.editor.currentId;
228+
const sandboxId = state.editor.currentSandbox.id;
229229
const templateId = state.editor.currentSandbox.customTemplate.id;
230230

231231
try {
@@ -247,7 +247,7 @@ export const editTemplate: AsyncAction<CustomTemplate> = async (
247247
) => {
248248
effects.analytics.track('Template - Edited', { source: 'editor' });
249249

250-
const sandboxId = state.editor.currentId;
250+
const sandboxId = state.editor.currentSandbox.id;
251251

252252
try {
253253
const updatedTemplate = await effects.api.updateTemplate(
@@ -270,7 +270,7 @@ export const addedTemplate: AsyncAction<{
270270
}> = async ({ state, actions, effects }, template) => {
271271
effects.analytics.track('Template - Created', { source: 'editor' });
272272

273-
const sandboxId = state.editor.currentId;
273+
const sandboxId = state.editor.currentSandbox.id;
274274

275275
try {
276276
const newTemplate = await effects.api.createTemplate(sandboxId, template);

0 commit comments

Comments
 (0)