Skip to content

Commit 6e788d3

Browse files
Fix smooth fork initial file selection on live
1 parent 4c494b8 commit 6e788d3

File tree

4 files changed

+32
-19
lines changed

4 files changed

+32
-19
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
import { NotificationStatus } from '@codesandbox/notifications';
1313

1414
import { createOptimisticModule } from './utils/common';
15-
import getItems from './utils/items';
1615
import { defaultOpenedModule, mainModule } from './utils/main-module';
1716
import { parseConfigurations } from './utils/parse-configurations';
1817
import { Action, AsyncAction } from '.';
@@ -260,11 +259,6 @@ export const setCurrentSandbox: AsyncAction<Sandbox> = async (
260259
state.workspace.project.description = sandbox.description || '';
261260
state.workspace.project.alias = sandbox.alias || '';
262261

263-
const items = getItems(state);
264-
const defaultItem = items.find(i => i.defaultOpen) || items[0];
265-
266-
state.workspace.openedWorkspaceItem = defaultItem.id;
267-
268262
await effects.executor.initializeExecutor(sandbox);
269263

270264
[

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { Action, AsyncAction } from 'app/overmind';
1111
import { withLoadApp, withOwnedSandbox } from 'app/overmind/factories';
1212
import { sortObjectByKeys } from 'app/overmind/utils/common';
13+
import getItems from 'app/overmind/utils/items';
1314
import {
1415
addDevToolsTab as addDevToolsTabUtil,
1516
closeDevToolsTab as closeDevToolsTabUtil,
@@ -101,6 +102,11 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
101102
await effects.vscode.closeAllTabs();
102103

103104
actions.internal.setCurrentSandbox(sandbox);
105+
106+
const items = getItems(state);
107+
const defaultItem = items.find(i => i.defaultOpen) || items[0];
108+
109+
state.workspace.openedWorkspaceItem = defaultItem.id;
104110
} catch (error) {
105111
state.editor.notFound = true;
106112
state.editor.error = error.message;

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { LiveMessage, LiveMessageEvent } from '@codesandbox/common/lib/types';
22
import { Action, AsyncAction, Operator } from 'app/overmind';
33
import { withLoadApp } from 'app/overmind/factories';
4+
import getItems from 'app/overmind/utils/items';
45
import { filter, fork, pipe } from 'overmind';
56

67
import * as internalActions from './internalActions';
@@ -19,10 +20,21 @@ export const roomJoined: AsyncAction<{
1920
state.currentModal = modal;
2021
}
2122

22-
actions.internal.setCurrentSandbox(sandbox);
23-
state.editor.modulesByPath = effects.vscode.fs.create(sandbox);
23+
await effects.vscode.closeAllTabs();
24+
await actions.internal.setCurrentSandbox(sandbox);
25+
26+
const items = getItems(state);
27+
const defaultItem = items.find(i => i.defaultOpen) || items[0];
28+
29+
state.workspace.openedWorkspaceItem = defaultItem.id;
30+
31+
state.editor.modulesByPath = effects.vscode.fs.create(
32+
state.editor.currentSandbox
33+
);
34+
2435
await effects.vscode.changeSandbox(sandbox);
2536
effects.vscode.openModule(state.editor.currentModule);
37+
effects.preview.executeCodeImmediately(true);
2638
state.live.isLoading = false;
2739
});
2840

@@ -31,8 +43,19 @@ export const createLiveClicked: AsyncAction<{
3143
}> = async ({ state, effects, actions }, { sandboxId }) => {
3244
effects.analytics.track('Create Live Session');
3345

46+
await effects.vscode.closeAllTabs();
47+
3448
const roomId = await effects.api.createLiveRoom(sandboxId);
35-
await actions.live.internal.initialize(roomId);
49+
const sandbox = await actions.live.internal.initialize(roomId);
50+
actions.internal.setCurrentSandbox(sandbox);
51+
52+
state.editor.modulesByPath = effects.vscode.fs.create(
53+
state.editor.currentSandbox
54+
);
55+
56+
await effects.vscode.changeSandbox(sandbox);
57+
effects.vscode.openModule(state.editor.currentModule);
58+
effects.preview.executeCodeImmediately(true);
3659
};
3760

3861
export const liveMessageReceived: Operator<LiveMessage> = pipe(

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,6 @@ export const initialize: AsyncAction<string, Sandbox> = async (
7272
}
7373
state.editor.currentId = sandbox.id;
7474

75-
await effects.vscode.closeAllTabs();
76-
77-
state.editor.modulesByPath = effects.vscode.fs.create(
78-
state.editor.currentSandbox
79-
);
80-
81-
await effects.vscode.changeSandbox(sandbox);
82-
effects.vscode.openModule(state.editor.currentModule);
83-
effects.preview.executeCodeImmediately(true);
84-
8575
effects.analytics.track('Live Session Joined', {});
8676
effects.live.listen(actions.live.liveMessageReceived);
8777

0 commit comments

Comments
 (0)