Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/app/src/app/overmind/effects/live/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export default new (class Live {
});
}

sendLiveMode(mode: string) {
sendLiveMode(mode: RoomInfo['mode']) {
return this.send('live:mode', {
mode,
});
Expand Down
45 changes: 25 additions & 20 deletions packages/app/src/app/overmind/namespaces/live/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { LiveMessage, LiveMessageEvent } from '@codesandbox/common/lib/types';
import {
LiveMessage,
LiveMessageEvent,
RoomInfo,
} from '@codesandbox/common/lib/types';
import { Action, AsyncAction, Operator } from 'app/overmind';
import { withLoadApp } from 'app/overmind/factories';
import getItems from 'app/overmind/utils/items';
Expand Down Expand Up @@ -176,41 +180,39 @@ export const onSelectionChanged: Action<any> = (
}
};

export const onModeChanged: Action<{ mode: string }> = (
{ state, effects },
{ mode }
export const onModeChanged: Action<RoomInfo['mode']> = (
{ effects, state },
mode
) => {
if (state.live.isOwner && state.live.roomInfo) {
state.live.roomInfo.mode = mode;
effects.live.sendLiveMode(mode);
}
};

export const onAddEditorClicked: Action<{
liveUserId: string;
}> = ({ state, effects }, { liveUserId }) => {
export const onAddEditorClicked: Action<string> = (
{ effects, state },
liveUserId
) => {
if (!state.live.roomInfo) {
return;
}

state.live.roomInfo.editorIds.push(liveUserId);

effects.live.sendEditorAdded(liveUserId);
};

export const onRemoveEditorClicked: Action<any> = (
{ state, effects },
{ liveUserId, data }
export const onRemoveEditorClicked: Action<string> = (
{ effects, state },
liveUserId
) => {
const userId = liveUserId || data.editor_user_id;

if (!state.live.roomInfo) {
return;
}

const editors = state.live.roomInfo.editorIds;
const newEditors = editors.filter(id => id !== userId);

state.live.roomInfo.editorIds = newEditors;
state.live.roomInfo.editorIds = editors.filter(id => id !== liveUserId);

effects.live.sendEditorRemoved(liveUserId);
};
Expand Down Expand Up @@ -249,21 +251,24 @@ export const onChatEnabledChange: Action<boolean> = (
}
};

export const onFollow: Action<{
liveUserId: string;
}> = ({ state, effects, actions }, { liveUserId }) => {
export const onFollow: Action<string> = (
{ actions, effects, state },
liveUserId
) => {
if (!state.live.roomInfo) {
return;
}

effects.analytics.track('Follow Along in Live');
state.live.followingUserId = liveUserId;

const user = state.live.roomInfo.users.find(u => u.id === liveUserId);
const user = state.live.roomInfo.users.find(({ id }) => id === liveUserId);

if (user && user.currentModuleShortid && state.editor.currentSandbox) {
const { modules } = state.editor.currentSandbox;
const module = modules.find(m => m.shortid === user.currentModuleShortid);
const module = modules.find(
({ shortid }) => shortid === user.currentModuleShortid
);

actions.editor.moduleSelected({
id: module ? module.id : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import {
LiveMessage,
LiveUser,
Module,
RoomInfo,
UserSelection,
} from '@codesandbox/common/lib/types';
import { NotificationStatus } from '@codesandbox/notifications/lib/state';
import { Operator } from 'app/overmind';
import { camelizeKeys } from 'humps';
import { json, mutate } from 'overmind';

import { Operator } from 'app/overmind';

export const onJoin: Operator<LiveMessage<{
status: 'connected';
live_user_id: string;
Expand Down Expand Up @@ -419,15 +421,16 @@ export const onUserCurrentModule: Operator<LiveMessage<{
});

export const onLiveMode: Operator<LiveMessage<{
mode: string;
}>> = mutate(({ state, actions }, { _isOwnMessage, data }) => {
mode: RoomInfo['mode'];
}>> = mutate(({ actions, state }, { _isOwnMessage, data }) => {
if (!state.live.roomInfo) {
return;
}

if (!_isOwnMessage) {
state.live.roomInfo.mode = data.mode;
}

actions.live.internal.clearUserSelections(null);
});

Expand Down
Loading