Skip to content

Commit 98505d6

Browse files
authored
Fix team live session join switching (codesandbox#2450)
* fix enum * fix live handling refetchsandbox * Finish team live switching
1 parent fb10378 commit 98505d6

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,15 @@ export const refetchSandboxInfo: AsyncAction = async ({
219219
sandbox.title = updatedSandbox.title;
220220
sandbox.team = updatedSandbox.team;
221221

222-
if (state.live.isLive) {
223-
await actions.live.internal.disconnect();
222+
state.live.isTeam = Boolean(sandbox.team);
224223

225-
if (sandbox.owned && sandbox.roomId) {
226-
state.live.isTeam = Boolean(sandbox.team);
227-
}
224+
if (sandbox.roomId === updatedSandbox.roomId) {
225+
return;
226+
}
228227

228+
sandbox.roomId = updatedSandbox.roomId;
229+
await actions.live.internal.disconnect();
230+
if (updatedSandbox.owned && updatedSandbox.roomId) {
229231
await actions.live.internal.initialize(sandbox.roomId);
230232
}
231233
}

packages/app/src/app/overmind/effects/live/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ export default {
8282
return _socket;
8383
},
8484
disconnect() {
85+
if (!channel) {
86+
return Promise.resolve({});
87+
}
88+
8589
return new Promise((resolve, reject) => {
8690
channel
8791
.leave()

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
109109
state.live.isTeam = true;
110110
}
111111

112-
state.live.isLoading = true;
113112
await actions.live.internal.initialize(sandbox.roomId);
114-
state.live.isLoading = false;
115113
} else if (sandbox.owned) {
116114
actions.files.internal.recoverFiles();
117115
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ export const createLiveClicked: AsyncAction<{
3030

3131
const roomId = await effects.api.createLiveRoom(sandboxId);
3232
await actions.live.internal.initialize(roomId);
33-
34-
state.live.isLoading = false;
3533
};
3634

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ export const initialize: AsyncAction<string, Sandbox> = async (
8080
return sandbox;
8181
} catch (error) {
8282
state.live.error = error.reason;
83+
} finally {
84+
state.live.isLoading = false;
8385
}
8486

8587
return null;

0 commit comments

Comments
 (0)