Skip to content

Commit f38a0e3

Browse files
Cleanup Live screen (#4027)
1 parent f10c0d5 commit f38a0e3

File tree

16 files changed

+516
-478
lines changed

16 files changed

+516
-478
lines changed

packages/app/src/app/overmind/effects/live/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ class Live {
413413
});
414414
}
415415

416-
sendLiveMode(mode: string) {
416+
sendLiveMode(mode: RoomInfo['mode']) {
417417
return this.send('live:mode', {
418418
mode,
419419
});

packages/app/src/app/overmind/namespaces/editor/actions.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,11 +608,7 @@ export const forkExternalSandbox: AsyncAction<{
608608
}
609609
};
610610

611-
export const forkSandboxClicked: AsyncAction = async ({
612-
state,
613-
effects,
614-
actions,
615-
}) => {
611+
export const forkSandboxClicked: AsyncAction = async ({ actions, state }) => {
616612
if (!state.editor.currentSandbox) {
617613
return;
618614
}

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

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
IModuleStateModule,
33
LiveMessage,
44
LiveMessageEvent,
5+
RoomInfo,
56
UserSelection,
67
UserViewRange,
78
} from '@codesandbox/common/lib/types';
@@ -275,41 +276,40 @@ export const onSelectionChanged: Action<UserSelection> = (
275276
}
276277
};
277278

278-
export const onModeChanged: Action<{ mode: string }> = (
279-
{ state, effects },
280-
{ mode }
279+
export const onModeChanged: Action<RoomInfo['mode']> = (
280+
{ effects, state },
281+
mode
281282
) => {
282283
if (state.live.isOwner && state.live.roomInfo) {
283284
state.live.roomInfo.mode = mode;
284285
effects.live.sendLiveMode(mode);
285286
}
286287
};
287288

288-
export const onAddEditorClicked: Action<{
289-
liveUserId: string;
290-
}> = ({ state, effects }, { liveUserId }) => {
289+
export const onAddEditorClicked: Action<string> = (
290+
{ effects, state },
291+
liveUserId
292+
) => {
291293
if (!state.live.roomInfo) {
292294
return;
293295
}
296+
294297
state.live.roomInfo.editorIds.push(liveUserId);
295298

296299
effects.live.sendEditorAdded(liveUserId);
297300
};
298301

299-
export const onRemoveEditorClicked: Action<any> = (
300-
{ state, effects },
301-
{ liveUserId, data }
302+
export const onRemoveEditorClicked: Action<string> = (
303+
{ effects, state },
304+
liveUserId
302305
) => {
303-
const userId = liveUserId || data.editor_user_id;
304-
305306
if (!state.live.roomInfo) {
306307
return;
307308
}
308309

309-
const editors = state.live.roomInfo.editorIds;
310-
const newEditors = editors.filter(id => id !== userId);
311-
312-
state.live.roomInfo.editorIds = newEditors;
310+
state.live.roomInfo.editorIds = state.live.roomInfo.editorIds.filter(
311+
id => id !== liveUserId
312+
);
313313

314314
effects.live.sendEditorRemoved(liveUserId);
315315
};
@@ -346,16 +346,17 @@ export const onChatEnabledToggle: Action = ({ effects, state }) => {
346346
}
347347
};
348348

349-
export const onFollow: Action<{
350-
liveUserId: string;
351-
}> = ({ state, effects, actions }, { liveUserId }) => {
349+
export const onFollow: Action<string> = (
350+
{ actions, effects, state },
351+
liveUserId
352+
) => {
352353
if (!state.live.roomInfo) {
353354
return;
354355
}
355356

356357
effects.analytics.track('Follow Along in Live');
357358
state.live.followingUserId = liveUserId;
358-
actions.live.revealViewRange({ liveUserId });
359+
actions.live.revealViewRange(liveUserId);
359360

360361
if (state.editor.currentModule) {
361362
// In case the selections were hidden first
@@ -395,15 +396,15 @@ export const onStopFollow: Action = ({ state, effects, actions }) => {
395396
}
396397
};
397398

398-
export const revealViewRange: Action<{ liveUserId: string }> = (
399-
{ state, effects, actions },
400-
{ liveUserId }
399+
export const revealViewRange: Action<string> = (
400+
{ actions, effects, state },
401+
liveUserId
401402
) => {
402403
if (!state.live.roomInfo) {
403404
return;
404405
}
405406

406-
const user = state.live.roomInfo.users.find(u => u.id === liveUserId);
407+
const user = state.live.roomInfo.users.find(({ id }) => id === liveUserId);
407408

408409
if (user && user.currentModuleShortid && state.editor.currentSandbox) {
409410
const { modules } = state.editor.currentSandbox;

packages/app/src/app/overmind/namespaces/live/liveMessageOperators.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ import {
55
LiveMessage,
66
LiveUser,
77
Module,
8+
RoomInfo,
89
UserSelection,
910
UserViewRange,
1011
} from '@codesandbox/common/lib/types';
1112
import { logBreadcrumb } from '@codesandbox/common/lib/utils/analytics/sentry';
1213
import { NotificationStatus } from '@codesandbox/notifications/lib/state';
13-
import { Operator } from 'app/overmind';
14-
import { getSavedCode } from 'app/overmind/utils/sandbox';
1514
import { camelizeKeys } from 'humps';
1615
import { json, mutate } from 'overmind';
1716

17+
import { Operator } from 'app/overmind';
18+
import { getSavedCode } from 'app/overmind/utils/sandbox';
19+
1820
export const onSave: Operator<LiveMessage<{
1921
saved_code: string;
2022
updated_at: string;
@@ -553,8 +555,8 @@ export const onUserViewRange: Operator<LiveMessage<{
553555
});
554556

555557
export const onLiveMode: Operator<LiveMessage<{
556-
mode: string;
557-
}>> = mutate(({ state, actions }, { _isOwnMessage, data }) => {
558+
mode: RoomInfo['mode'];
559+
}>> = mutate(({ actions, state }, { _isOwnMessage, data }) => {
558560
if (!state.live.roomInfo) {
559561
return;
560562
}

packages/app/src/app/pages/Sandbox/Editor/Header/CollaboratorHeads/CollaboratorHeads.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export const CollaboratorHeads: FunctionComponent = () => {
138138
if (liveUserId === user.id || followingUserId === user.id) {
139139
actions.live.onStopFollow();
140140
} else {
141-
actions.live.onFollow({ liveUserId: user.id });
141+
actions.live.onFollow(user.id);
142142
}
143143
};
144144

0 commit comments

Comments
 (0)