Skip to content

Commit fec6593

Browse files
committed
🔨 Switch Live to use useOvermind
1 parent f10c0d5 commit fec6593

File tree

7 files changed

+179
-184
lines changed

7 files changed

+179
-184
lines changed

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

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@ import * as liveMessage from './liveMessageOperators';
1717

1818
export const internal = internalActions;
1919

20-
export const signInToRoom: AsyncAction<{
21-
roomId: string;
22-
}> = withLoadApp(async ({ state, effects, actions }, { roomId }) => {
23-
await actions.internal.signIn({});
24-
25-
if (state.isLoggedIn) {
26-
await actions.live.roomJoined({
27-
roomId,
28-
});
20+
export const signInToRoom: AsyncAction<string> = withLoadApp(
21+
async ({ actions, state }, roomId) => {
22+
await actions.internal.signIn({});
23+
24+
if (state.isLoggedIn) {
25+
await actions.live.roomJoined(roomId);
26+
}
2927
}
30-
});
28+
);
3129

3230
export const onOperationError: Action<{
3331
moduleShortid: string;
@@ -39,57 +37,57 @@ export const onOperationError: Action<{
3937
});
4038
};
4139

42-
export const roomJoined: AsyncAction<{
43-
roomId: string;
44-
}> = withLoadApp(async ({ state, effects, actions }, { roomId }) => {
45-
if (!state.isLoggedIn) {
46-
return;
47-
}
40+
export const roomJoined: AsyncAction<string> = withLoadApp(
41+
async ({ actions, effects, state }, roomId) => {
42+
if (!state.isLoggedIn) {
43+
return;
44+
}
4845

49-
await effects.vscode.initialized;
50-
await effects.vscode.closeAllTabs();
46+
await effects.vscode.initialized;
47+
await effects.vscode.closeAllTabs();
5148

52-
state.live.joinSource = 'live';
49+
state.live.joinSource = 'live';
5350

54-
if (state.live.isLive) {
55-
actions.live.internal.disconnect();
56-
}
51+
if (state.live.isLive) {
52+
actions.live.internal.disconnect();
53+
}
5754

58-
const sandbox = await actions.live.internal.initialize(roomId);
55+
const sandbox = await actions.live.internal.initialize(roomId);
5956

60-
if (!sandbox) {
61-
return;
62-
}
57+
if (!sandbox) {
58+
return;
59+
}
6360

64-
if (state.updateStatus === 'available') {
65-
const modal = 'liveVersionMismatch';
66-
effects.analytics.track('Open Modal', { modal });
67-
state.currentModal = modal;
68-
}
61+
if (state.updateStatus === 'available') {
62+
const modal = 'liveVersionMismatch';
63+
effects.analytics.track('Open Modal', { modal });
64+
state.currentModal = modal;
65+
}
6966

70-
await actions.internal.setCurrentSandbox(sandbox);
67+
await actions.internal.setCurrentSandbox(sandbox);
7168

72-
actions.editor.listenToSandboxChanges({ sandboxId: sandbox.id });
73-
const items = getItems(state);
74-
const defaultItem = items.find(i => i.defaultOpen) || items[0];
69+
actions.editor.listenToSandboxChanges({ sandboxId: sandbox.id });
70+
const items = getItems(state);
71+
const defaultItem = items.find(i => i.defaultOpen) || items[0];
7572

76-
state.workspace.openedWorkspaceItem = defaultItem.id;
73+
state.workspace.openedWorkspaceItem = defaultItem.id;
7774

78-
await effects.vscode.changeSandbox(sandbox, fs => {
79-
state.editor.modulesByPath = fs;
80-
});
75+
await effects.vscode.changeSandbox(sandbox, fs => {
76+
state.editor.modulesByPath = fs;
77+
});
8178

82-
effects.vscode.openModule(state.editor.currentModule);
79+
effects.vscode.openModule(state.editor.currentModule);
8380

84-
if (
85-
sandbox.featureFlags.comments &&
86-
hasPermission(sandbox.authorization, 'comment')
87-
) {
88-
actions.comments.getSandboxComments(sandbox.id);
89-
}
81+
if (
82+
sandbox.featureFlags.comments &&
83+
hasPermission(sandbox.authorization, 'comment')
84+
) {
85+
actions.comments.getSandboxComments(sandbox.id);
86+
}
9087

91-
state.editor.isLoading = false;
92-
});
88+
state.editor.isLoading = false;
89+
}
90+
);
9391

9492
export const createLiveClicked: AsyncAction<string> = async (
9593
{ actions, effects, state },

‎packages/app/src/app/pages/Live/BlinkingDot.tsx‎

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Button, Text } from '@codesandbox/components';
2+
import css from '@styled-system/css';
3+
import React, { FunctionComponent } from 'react';
4+
import { Link } from 'react-router-dom';
5+
6+
export const RoomNotFoundError: FunctionComponent = () => (
7+
<>
8+
<Text size={6} weight="bold">
9+
Something went wrong
10+
</Text>
11+
12+
<Text block marginTop={4} size={4}>
13+
{`It seems like this session doesn't exist or has been closed`}
14+
</Text>
15+
16+
<Link css={css({ textDecoration: 'none' })} to="/s">
17+
<Button marginTop={5}>Create Sandbox</Button>
18+
</Link>
19+
</>
20+
);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Button, Text } from '@codesandbox/components';
2+
import css from '@styled-system/css';
3+
import React, { FunctionComponent } from 'react';
4+
import { Link } from 'react-router-dom';
5+
6+
import { useOvermind } from 'app/overmind';
7+
8+
import { RoomNotFoundError } from './RoomNotFoundError';
9+
10+
export const Error: FunctionComponent = () => {
11+
const {
12+
state: {
13+
live: { error },
14+
},
15+
} = useOvermind();
16+
17+
if (error === 'room not found') {
18+
return <RoomNotFoundError />;
19+
}
20+
21+
return (
22+
<>
23+
<Text size={6} weight="bold">
24+
An error occurred while connecting to the live session:
25+
</Text>
26+
27+
<Text block marginTop={4} size={4}>
28+
{error}
29+
</Text>
30+
31+
<Link css={css({ textDecoration: 'none' })} to="/s">
32+
<Button marginTop={5}>Create Sandbox</Button>
33+
</Link>
34+
</>
35+
);
36+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Button, Element, Stack, Text } from '@codesandbox/components';
2+
import React, { FunctionComponent } from 'react';
3+
import GithubIcon from 'react-icons/lib/go/mark-github';
4+
import { useParams } from 'react-router-dom';
5+
6+
import { useOvermind } from 'app/overmind';
7+
8+
export const NotAuthenticated: FunctionComponent = () => {
9+
const {
10+
actions: {
11+
live: { signInToRoom },
12+
},
13+
} = useOvermind();
14+
const { roomId } = useParams();
15+
16+
return (
17+
<>
18+
<Text weight="bold" size={6}>
19+
Sign in required
20+
</Text>
21+
22+
<Text block marginTop={4} size={4}>
23+
You need to sign in to join this session
24+
</Text>
25+
26+
<Element marginTop={4}>
27+
<Button onClick={() => signInToRoom(roomId)} autoWidth>
28+
<Stack gap={2} align="center">
29+
<GithubIcon />{' '}
30+
<Text style={{ lineHeight: 1 }}>Sign in with GitHub</Text>
31+
</Stack>
32+
</Button>
33+
</Element>
34+
</>
35+
);
36+
};

0 commit comments

Comments
 (0)