Skip to content

Commit b32eacd

Browse files
committed
🔨 Switch Live to use useOvermind
1 parent d7d69f1 commit b32eacd

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;
@@ -37,50 +35,50 @@ export const onOperationError: Action<{
3735
});
3836
};
3937

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

47-
await effects.vscode.initialized;
48-
await effects.vscode.closeAllTabs();
44+
await effects.vscode.initialized;
45+
await effects.vscode.closeAllTabs();
4946

50-
state.live.joinSource = 'live';
47+
state.live.joinSource = 'live';
5148

52-
if (state.live.isLive) {
53-
actions.live.internal.disconnect();
54-
}
49+
if (state.live.isLive) {
50+
actions.live.internal.disconnect();
51+
}
5552

56-
const sandbox = await actions.live.internal.initialize(roomId);
53+
const sandbox = await actions.live.internal.initialize(roomId);
5754

58-
if (!sandbox) {
59-
return;
60-
}
55+
if (!sandbox) {
56+
return;
57+
}
6158

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

68-
await actions.internal.setCurrentSandbox(sandbox);
65+
await actions.internal.setCurrentSandbox(sandbox);
6966

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

74-
state.workspace.openedWorkspaceItem = defaultItem.id;
71+
state.workspace.openedWorkspaceItem = defaultItem.id;
7572

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

80-
effects.live.sendModuleStateSyncRequest();
81-
effects.vscode.openModule(state.editor.currentModule);
82-
state.editor.isLoading = false;
83-
});
77+
effects.live.sendModuleStateSyncRequest();
78+
effects.vscode.openModule(state.editor.currentModule);
79+
state.editor.isLoading = false;
80+
}
81+
);
8482

8583
export const createLiveClicked: AsyncAction<string> = async (
8684
{ 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)