Skip to content

Commit cdab9e4

Browse files
author
Saagar Takhi
committed
Refactors /Sandbox/Editor/Workspace/items/Live/index.js to replace Cerebral with Overmind & convert js to tsx
1 parent 8a2bad7 commit cdab9e4

File tree

3 files changed

+128
-99
lines changed

3 files changed

+128
-99
lines changed

packages/app/src/app/pages/Sandbox/Editor/Workspace/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import ConfigurationFiles from './items/ConfigurationFiles';
2222
import { Deployment } from './items/Deployment';
2323
import { FilesItem } from './items/Files';
2424
import { GitHub } from './items/GitHub';
25-
import Live from './items/Live';
25+
import { Live } from './items/Live';
2626
import { More } from './items/More';
2727
import { NotOwnedSandboxInfo } from './items/NotOwnedSandboxInfo';
2828
import { ProjectInfo } from './items/ProjectInfo';

packages/app/src/app/pages/Sandbox/Editor/Workspace/items/Live/index.js

Lines changed: 0 additions & 98 deletions
This file was deleted.
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import React, { FunctionComponent } from 'react';
2+
import { useOvermind } from 'app/overmind';
3+
4+
import LiveInfo from './LiveInfo';
5+
import LiveButton from './LiveButton';
6+
7+
import {
8+
Description,
9+
WorkspaceInputContainer,
10+
WorkspaceSubtitle,
11+
ErrorDescription,
12+
} from '../../elements';
13+
import { More } from '../More';
14+
15+
export const Live: FunctionComponent = () => {
16+
const {
17+
state: {
18+
isLoggedIn,
19+
live: {
20+
isLive,
21+
isOwner,
22+
isTeam,
23+
roomInfo,
24+
liveUserId,
25+
reconnecting,
26+
notificationsHidden,
27+
followingUserId,
28+
isLoading,
29+
},
30+
editor: {
31+
isAllModulesSynced,
32+
currentSandbox: { owned },
33+
currentId,
34+
},
35+
},
36+
actions: {
37+
live: {
38+
onModeChanged,
39+
onAddEditorClicked,
40+
onRemoveEditorClicked,
41+
onSessionCloseClicked,
42+
onToggleNotificationsHidden,
43+
onChatEnabledChange,
44+
onFollow,
45+
createLiveClicked,
46+
},
47+
},
48+
} = useOvermind();
49+
const hasUnsyncedModules = !isAllModulesSynced;
50+
51+
const showPlaceHolder = (!isLive && !owned) || !isLoggedIn;
52+
53+
if (showPlaceHolder) {
54+
const message = isLoggedIn ? (
55+
<>
56+
You need to own this sandbox to open a live session to collaborate with
57+
others in real time.{' '}
58+
<p>Fork this sandbox to live share it with others!</p>
59+
</>
60+
) : (
61+
`You need to be signed in to open a live session to collaborate with others in real time. Sign in to live share this sandbox!`
62+
);
63+
64+
return <More message={message} id="live" />;
65+
}
66+
67+
return (
68+
<div>
69+
{isLive ? (
70+
<LiveInfo
71+
setMode={onModeChanged}
72+
addEditor={onAddEditorClicked}
73+
removeEditor={onRemoveEditorClicked}
74+
isOwner={isOwner}
75+
isTeam={isTeam}
76+
roomInfo={roomInfo}
77+
ownerIds={roomInfo.ownerIds}
78+
currentUserId={liveUserId}
79+
reconnecting={reconnecting}
80+
onSessionCloseClicked={onSessionCloseClicked}
81+
notificationsHidden={notificationsHidden}
82+
toggleNotificationsHidden={onToggleNotificationsHidden}
83+
chatEnabled={roomInfo.chatEnabled}
84+
toggleChatEnabled={() => {
85+
onChatEnabledChange({
86+
enabled: !roomInfo.chatEnabled,
87+
});
88+
}}
89+
setFollowing={onFollow}
90+
followingUserId={followingUserId}
91+
/>
92+
) : (
93+
<>
94+
<Description style={{ marginBottom: '1rem' }}>
95+
Invite others to live edit this sandbox with you. We
96+
{"'"}
97+
re doing it live!
98+
</Description>
99+
100+
<>
101+
<WorkspaceSubtitle>Create live room</WorkspaceSubtitle>
102+
<Description>
103+
To invite others you need to generate a URL that others can join.
104+
</Description>
105+
106+
{hasUnsyncedModules && (
107+
<ErrorDescription>
108+
Save all your files before going live
109+
</ErrorDescription>
110+
)}
111+
<WorkspaceInputContainer>
112+
<LiveButton
113+
onClick={() => {
114+
createLiveClicked({
115+
sandboxId: currentId,
116+
});
117+
}}
118+
isLoading={isLoading}
119+
disable={hasUnsyncedModules}
120+
/>
121+
</WorkspaceInputContainer>
122+
</>
123+
</>
124+
)}
125+
</div>
126+
);
127+
};

0 commit comments

Comments
 (0)