Skip to content

Commit d1c26f3

Browse files
committed
🔨 Switch Live to use useOvermind
1 parent 3bd0095 commit d1c26f3

File tree

9 files changed

+209
-193
lines changed

9 files changed

+209
-193
lines changed

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

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@ import { IModuleStateModule } from './types';
1515

1616
export const internal = internalActions;
1717

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

3028
export const onOperationError: Action<{
3129
moduleShortid: string;
@@ -55,50 +53,50 @@ export const onOperationError: Action<{
5553
effects.vscode.setModuleCode(module);
5654
};
5755

58-
export const roomJoined: AsyncAction<{
59-
roomId: string;
60-
}> = withLoadApp(async ({ state, effects, actions }, { roomId }) => {
61-
if (!state.isLoggedIn) {
62-
return;
63-
}
56+
export const roomJoined: AsyncAction<string> = withLoadApp(
57+
async ({ actions, effects, state }, roomId) => {
58+
if (!state.isLoggedIn) {
59+
return;
60+
}
6461

65-
await effects.vscode.initialized;
66-
await effects.vscode.closeAllTabs();
62+
await effects.vscode.initialized;
63+
await effects.vscode.closeAllTabs();
6764

68-
state.live.joinSource = 'live';
65+
state.live.joinSource = 'live';
6966

70-
if (state.live.isLive) {
71-
actions.live.internal.disconnect();
72-
}
67+
if (state.live.isLive) {
68+
actions.live.internal.disconnect();
69+
}
7370

74-
const sandbox = await actions.live.internal.initialize(roomId);
71+
const sandbox = await actions.live.internal.initialize(roomId);
7572

76-
if (!sandbox) {
77-
return;
78-
}
73+
if (!sandbox) {
74+
return;
75+
}
7976

80-
if (state.updateStatus === 'available') {
81-
const modal = 'liveVersionMismatch';
82-
effects.analytics.track('Open Modal', { modal });
83-
state.currentModal = modal;
84-
}
77+
if (state.updateStatus === 'available') {
78+
const modal = 'liveVersionMismatch';
79+
effects.analytics.track('Open Modal', { modal });
80+
state.currentModal = modal;
81+
}
8582

86-
await actions.internal.setCurrentSandbox(sandbox);
83+
await actions.internal.setCurrentSandbox(sandbox);
8784

88-
actions.editor.listenToSandboxChanges({ sandboxId: sandbox.id });
89-
const items = getItems(state);
90-
const defaultItem = items.find(i => i.defaultOpen) || items[0];
85+
actions.editor.listenToSandboxChanges({ sandboxId: sandbox.id });
86+
const items = getItems(state);
87+
const defaultItem = items.find(i => i.defaultOpen) || items[0];
9188

92-
state.workspace.openedWorkspaceItem = defaultItem.id;
89+
state.workspace.openedWorkspaceItem = defaultItem.id;
9390

94-
await effects.vscode.changeSandbox(sandbox, fs => {
95-
state.editor.modulesByPath = fs;
96-
});
91+
await effects.vscode.changeSandbox(sandbox, fs => {
92+
state.editor.modulesByPath = fs;
93+
});
9794

98-
effects.live.sendModuleStateSyncRequest();
99-
effects.vscode.openModule(state.editor.currentModule);
100-
state.editor.isLoading = false;
101-
});
95+
effects.live.sendModuleStateSyncRequest();
96+
effects.vscode.openModule(state.editor.currentModule);
97+
state.editor.isLoading = false;
98+
}
99+
);
102100

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

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

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React, { FunctionComponent } from 'react';
2+
import { Link } from 'react-router-dom';
3+
4+
import { Notice, Title } from '../elements';
5+
6+
export const RoomNotFoundError: FunctionComponent = () => (
7+
<>
8+
<Notice>Something went wrong</Notice>
9+
10+
<Title>
11+
{`It seems like this session doesn't exist or has been closed`}
12+
</Title>
13+
14+
<br />
15+
16+
<Link to="/s">Create Sandbox</Link>
17+
</>
18+
);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, { FunctionComponent } from 'react';
2+
import { Link } from 'react-router-dom';
3+
4+
import { SubTitle } from 'app/components/SubTitle';
5+
import { Title } from 'app/components/Title';
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+
<Title>An error occured while connecting to the live session:</Title>
24+
25+
<SubTitle>{error}</SubTitle>
26+
27+
<br />
28+
29+
<br />
30+
31+
<Link to="/s">Create Sandbox</Link>
32+
</>
33+
);
34+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import GithubIconBase from 'react-icons/lib/go/mark-github';
2+
import styled from 'styled-components';
3+
4+
export const GitHubIcon = styled(GithubIconBase)`
5+
margin-right: 0.5rem;
6+
`;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Button } from '@codesandbox/common/lib/components/Button';
2+
import Row from '@codesandbox/common/lib/components/flex/Row';
3+
import React, { FunctionComponent } from 'react';
4+
5+
import { useOvermind } from 'app/overmind';
6+
7+
import { Notice, Title } from '../elements';
8+
9+
import { GitHubIcon } from './elements';
10+
11+
type Props = {
12+
roomId: string;
13+
};
14+
export const NotAuthenticated: FunctionComponent<Props> = ({ roomId }) => {
15+
const {
16+
actions: {
17+
live: { signInToRoom },
18+
},
19+
} = useOvermind();
20+
21+
return (
22+
<>
23+
<Notice>Sign in required</Notice>
24+
25+
<Title>You need to sign in to join this session</Title>
26+
27+
<br />
28+
29+
<div>
30+
<Button onClick={() => signInToRoom(roomId)} small>
31+
<Row>
32+
<GitHubIcon /> Sign in with GitHub
33+
</Row>
34+
</Button>
35+
</div>
36+
</>
37+
);
38+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import CenteredBase from '@codesandbox/common/lib/components/flex/Centered';
2+
import PaddingBase from '@codesandbox/common/lib/components/spacing/Padding';
3+
import styled from 'styled-components';
4+
5+
import { Title as TitleBase } from 'app/components/Title';
6+
7+
export const Centered = styled(CenteredBase)`
8+
flex: 1;
9+
width: 100%;
10+
height: 100%;
11+
`;
12+
13+
export const Notice = styled.div`
14+
font-weight: 300;
15+
color: rgba(255, 255, 255, 0.5);
16+
margin-bottom: 1rem;
17+
font-size: 1.5rem;
18+
`;
19+
20+
export const Padding = styled(PaddingBase)`
21+
display: flex;
22+
flex-direction: column;
23+
width: 100vw;
24+
height: 100vh;
25+
`;
26+
27+
export const Title = styled(TitleBase)`
28+
font-size: 1.25rem;
29+
`;

0 commit comments

Comments
 (0)