Skip to content

Commit 0917991

Browse files
committed
🔨 Switch Live to use useOvermind
1 parent 179d7f9 commit 0917991

File tree

12 files changed

+269
-216
lines changed

12 files changed

+269
-216
lines changed

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

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,58 @@ import * as liveMessage from './liveMessageOperators';
99

1010
export const internal = internalActions;
1111

12-
export const signInToRoom: AsyncAction<{
13-
roomId: string;
14-
}> = withLoadApp(async ({ state, effects, actions }, { roomId }) => {
15-
await actions.internal.signIn({});
16-
17-
if (state.isLoggedIn) {
18-
await actions.live.roomJoined({
19-
roomId,
20-
});
21-
}
22-
});
12+
export const signInToRoom: AsyncAction<string> = withLoadApp(
13+
async ({ actions, state }, roomId) => {
14+
await actions.internal.signIn({});
2315

24-
export const roomJoined: AsyncAction<{
25-
roomId: string;
26-
}> = withLoadApp(async ({ state, effects, actions }, { roomId }) => {
27-
if (!state.isLoggedIn) {
28-
return;
16+
if (state.isLoggedIn) {
17+
await actions.live.roomJoined(roomId);
18+
}
2919
}
20+
);
3021

31-
await effects.vscode.initialized;
32-
await effects.vscode.closeAllTabs();
22+
export const roomJoined: AsyncAction<string> = withLoadApp(
23+
async ({ actions, effects, state }, roomId) => {
24+
if (!state.isLoggedIn) {
25+
return;
26+
}
3327

34-
if (state.live.isLive) {
35-
actions.live.internal.disconnect();
36-
}
28+
await effects.vscode.initialized;
29+
await effects.vscode.closeAllTabs();
3730

38-
const sandbox = await actions.live.internal.initialize(roomId);
31+
if (state.live.isLive) {
32+
actions.live.internal.disconnect();
33+
}
3934

40-
if (!sandbox) {
41-
return;
42-
}
35+
const sandbox = await actions.live.internal.initialize(roomId);
4336

44-
if (state.updateStatus === 'available') {
45-
const modal = 'liveVersionMismatch';
46-
effects.analytics.track('Open Modal', { modal });
47-
state.currentModal = modal;
48-
}
37+
if (!sandbox) {
38+
return;
39+
}
4940

50-
await actions.internal.setCurrentSandbox(sandbox);
41+
if (state.updateStatus === 'available') {
42+
const modal = 'liveVersionMismatch';
43+
effects.analytics.track('Open Modal', { modal });
44+
state.currentModal = modal;
45+
}
5146

52-
const items = getItems(state);
53-
const defaultItem = items.find(i => i.defaultOpen) || items[0];
47+
await actions.internal.setCurrentSandbox(sandbox);
5448

55-
state.workspace.openedWorkspaceItem = defaultItem.id;
49+
const items = getItems(state);
50+
const defaultItem = items.find(i => i.defaultOpen) || items[0];
5651

57-
await effects.vscode.changeSandbox(sandbox, fs => {
58-
state.editor.modulesByPath = fs;
59-
});
52+
state.workspace.openedWorkspaceItem = defaultItem.id;
6053

61-
effects.live.sendModuleStateSyncRequest();
62-
effects.vscode.openModule(state.editor.currentModule);
63-
effects.preview.executeCodeImmediately({ initialRender: true });
64-
state.editor.isLoading = false;
65-
});
54+
await effects.vscode.changeSandbox(sandbox, fs => {
55+
state.editor.modulesByPath = fs;
56+
});
57+
58+
effects.live.sendModuleStateSyncRequest();
59+
effects.vscode.openModule(state.editor.currentModule);
60+
effects.preview.executeCodeImmediately({ initialRender: true });
61+
state.editor.isLoading = false;
62+
}
63+
);
6664

6765
export const createLiveClicked: AsyncAction<string> = async (
6866
{ 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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import RecordIconBase from 'react-icons/lib/md/fiber-manual-record';
2+
import styled, { css } from 'styled-components';
3+
4+
export const Container = styled.div`
5+
font-size: 4rem;
6+
display: block;
7+
color: rgb(253, 36, 57);
8+
9+
svg {
10+
transition: 0.3s ease opacity;
11+
}
12+
`;
13+
14+
export const RecordIcon = styled(RecordIconBase)<{ showing: boolean }>`
15+
${({ showing }) => css`
16+
opacity: ${showing ? 1 : 0};
17+
`};
18+
`;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React, { FunctionComponent, useEffect, useState } from 'react';
2+
3+
import { Container, RecordIcon } from './elements';
4+
5+
export const BlinkingDot: FunctionComponent = () => {
6+
const [showing, setShowing] = useState(true);
7+
8+
useEffect(() => {
9+
const timer = setInterval(() => setShowing(show => !show), 1000);
10+
11+
return () => clearInterval(timer);
12+
});
13+
14+
return (
15+
<Container>
16+
<RecordIcon showing={showing} />
17+
</Container>
18+
);
19+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React, { FunctionComponent } from 'react';
2+
3+
import { Skeleton } from 'app/components/Skeleton';
4+
5+
import { BlinkingDot } from './BlinkingDot';
6+
7+
export const Loading: FunctionComponent = () => (
8+
<Skeleton
9+
titles={[
10+
{
11+
content: <BlinkingDot />,
12+
delay: 0,
13+
},
14+
{
15+
content: 'Joining Live Session...',
16+
delay: 0.5,
17+
},
18+
]}
19+
/>
20+
);
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)