Skip to content

Commit 4e0eea9

Browse files
select correct workspace item when forking
1 parent 212741b commit 4e0eea9

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from '@codesandbox/common/lib/types';
1010
import { Action, AsyncAction } from 'app/overmind';
1111
import { withLoadApp, withOwnedSandbox } from 'app/overmind/factories';
12-
import getItems from 'app/overmind/utils/items';
1312
import {
1413
addDevToolsTab as addDevToolsTabUtil,
1514
closeDevToolsTab as closeDevToolsTabUtil,
@@ -95,10 +94,7 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
9594

9695
actions.internal.setCurrentSandbox(sandbox);
9796

98-
const items = getItems(state);
99-
const defaultItem = items.find(i => i.defaultOpen) || items[0];
100-
101-
state.workspace.openedWorkspaceItem = defaultItem.id;
97+
actions.workspace.openDefaultItem();
10298
} catch (error) {
10399
state.editor.notFound = true;
104100
state.editor.error = error.message;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ export const forkSandbox: AsyncAction<{
345345
forkedSandbox
346346
);
347347
effects.preview.updateAddressbarUrl();
348-
348+
actions.workspace.openDefaultItem();
349349
effects.notificationToast.success('Forked sandbox!');
350350
effects.router.updateSandboxUrl(forkedSandbox);
351351
} catch (error) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { CustomTemplate } from '@codesandbox/common/lib/types';
33
import slugify from '@codesandbox/common/lib/utils/slugify';
44
import { Action, AsyncAction } from 'app/overmind';
55
import { withOwnedSandbox } from 'app/overmind/factories';
6+
import getItems from 'app/overmind/utils/items';
67

78
export const valueChanged: Action<{
89
field: string;
@@ -285,3 +286,10 @@ export const addedTemplate: AsyncAction<{
285286
);
286287
}
287288
};
289+
290+
export const openDefaultItem: Action = ({ state }) => {
291+
const items = getItems(state);
292+
const defaultItem = items.find(i => i.defaultOpen) || items[0];
293+
294+
state.workspace.openedWorkspaceItem = defaultItem.id;
295+
};

0 commit comments

Comments
 (0)