|
| 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