Skip to content

Commit 551716f

Browse files
committed
🔨 Switch Live to use useOvermind
1 parent ce2da4f commit 551716f

File tree

2 files changed

+60
-67
lines changed
  • packages/app/src/app

2 files changed

+60
-67
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ export const roomJoined: AsyncAction<{
3737
state.live.isLoading = false;
3838
});
3939

40-
export const createLiveClicked: AsyncAction<{
41-
sandboxId: string;
42-
}> = async ({ state, effects, actions }, { sandboxId }) => {
40+
export const createLiveClicked: AsyncAction<string> = async (
41+
{ actions, effects },
42+
sandboxId
43+
) => {
4344
effects.analytics.track('Create Live Session');
4445

4546
const roomId = await effects.api.createLiveRoom(sandboxId);
@@ -176,9 +177,9 @@ export const onSendChat: Action<{ message: string }> = (
176177
effects.live.sendChat(message);
177178
};
178179

179-
export const onChatEnabledChange: Action<{ enabled: boolean }> = (
180+
export const onChatEnabledChange: Action<boolean> = (
180181
{ effects, state },
181-
{ enabled }
182+
enabled
182183
) => {
183184
effects.analytics.track('Enable Live Chat');
184185

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

Lines changed: 54 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
import { useOvermind } from 'app/overmind';
21
import React, { FunctionComponent } from 'react';
32

3+
import { useOvermind } from 'app/overmind';
4+
45
import {
56
Description,
67
ErrorDescription,
78
WorkspaceInputContainer,
89
WorkspaceSubtitle,
910
} from '../../elements';
11+
1012
import { More } from '../More';
13+
1114
import LiveButton from './LiveButton';
1215
import LiveInfo from './LiveInfo';
1316

1417
export const Live: FunctionComponent = () => {
1518
const {
19+
actions: {
20+
live: {
21+
createLiveClicked,
22+
onAddEditorClicked,
23+
onChatEnabledChange,
24+
onFollow,
25+
onModeChanged,
26+
onRemoveEditorClicked,
27+
onSessionCloseClicked,
28+
onToggleNotificationsHidden,
29+
},
30+
},
1631
state: {
17-
isLoggedIn,
32+
editor: {
33+
currentSandbox: { id, owned },
34+
isAllModulesSynced,
35+
},
1836
live: {
37+
followingUserId,
1938
isLive,
39+
isLoading,
2040
isOwner,
2141
isTeam,
22-
roomInfo,
2342
liveUserId,
24-
reconnecting,
2543
notificationsHidden,
26-
followingUserId,
27-
isLoading,
28-
},
29-
editor: {
30-
isAllModulesSynced,
31-
currentSandbox: { owned, id },
32-
},
33-
},
34-
actions: {
35-
live: {
36-
onModeChanged,
37-
onAddEditorClicked,
38-
onRemoveEditorClicked,
39-
onSessionCloseClicked,
40-
onToggleNotificationsHidden,
41-
onChatEnabledChange,
42-
onFollow,
43-
createLiveClicked,
44+
reconnecting,
45+
roomInfo,
4446
},
47+
isLoggedIn,
4548
},
4649
} = useOvermind();
47-
const hasUnsyncedModules = !isAllModulesSynced;
4850

49-
const showPlaceHolder = (!isLive && !owned) || !isLoggedIn;
50-
51-
if (showPlaceHolder) {
51+
if ((!isLive && !owned) || !isLoggedIn) {
5252
const message = isLoggedIn ? (
5353
<>
5454
You need to own this sandbox to open a live session to collaborate with
@@ -66,26 +66,22 @@ export const Live: FunctionComponent = () => {
6666
<div>
6767
{isLive ? (
6868
<LiveInfo
69-
setMode={onModeChanged}
7069
addEditor={onAddEditorClicked}
71-
removeEditor={onRemoveEditorClicked}
70+
chatEnabled={roomInfo.chatEnabled}
71+
currentUserId={liveUserId}
72+
followingUserId={followingUserId}
7273
isOwner={isOwner}
7374
isTeam={isTeam}
74-
roomInfo={roomInfo}
75+
notificationsHidden={notificationsHidden}
76+
onSessionCloseClicked={onSessionCloseClicked}
7577
ownerIds={roomInfo.ownerIds}
76-
currentUserId={liveUserId}
7778
reconnecting={reconnecting}
78-
onSessionCloseClicked={onSessionCloseClicked}
79-
notificationsHidden={notificationsHidden}
80-
toggleNotificationsHidden={onToggleNotificationsHidden}
81-
chatEnabled={roomInfo.chatEnabled}
82-
toggleChatEnabled={() => {
83-
onChatEnabledChange({
84-
enabled: !roomInfo.chatEnabled,
85-
});
86-
}}
79+
removeEditor={onRemoveEditorClicked}
80+
roomInfo={roomInfo}
8781
setFollowing={onFollow}
88-
followingUserId={followingUserId}
82+
setMode={onModeChanged}
83+
toggleChatEnabled={() => onChatEnabledChange(!roomInfo.chatEnabled)}
84+
toggleNotificationsHidden={onToggleNotificationsHidden}
8985
/>
9086
) : (
9187
<>
@@ -95,29 +91,25 @@ export const Live: FunctionComponent = () => {
9591
re doing it live!
9692
</Description>
9793

98-
<>
99-
<WorkspaceSubtitle>Create live room</WorkspaceSubtitle>
100-
<Description>
101-
To invite others you need to generate a URL that others can join.
102-
</Description>
94+
<WorkspaceSubtitle>Create live room</WorkspaceSubtitle>
95+
96+
<Description>
97+
To invite others you need to generate a URL that others can join.
98+
</Description>
99+
100+
{!isAllModulesSynced && (
101+
<ErrorDescription>
102+
Save all your files before going live
103+
</ErrorDescription>
104+
)}
103105

104-
{hasUnsyncedModules && (
105-
<ErrorDescription>
106-
Save all your files before going live
107-
</ErrorDescription>
108-
)}
109-
<WorkspaceInputContainer>
110-
<LiveButton
111-
onClick={() => {
112-
createLiveClicked({
113-
sandboxId: id,
114-
});
115-
}}
116-
isLoading={isLoading}
117-
disable={hasUnsyncedModules}
118-
/>
119-
</WorkspaceInputContainer>
120-
</>
106+
<WorkspaceInputContainer>
107+
<LiveButton
108+
disable={!isAllModulesSynced}
109+
isLoading={isLoading}
110+
onClick={() => createLiveClicked(id)}
111+
/>
112+
</WorkspaceInputContainer>
121113
</>
122114
)}
123115
</div>

0 commit comments

Comments
 (0)