Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single wrapper for multiplayer components #4511

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 4 additions & 5 deletions editor/src/components/canvas/controls/comment-indicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ import { jsx } from '@emotion/react'
import React from 'react'
import { CanvasOffsetWrapper } from './canvas-offset-wrapper'
import { EditorModes } from '../../editor/editor-modes'
import { ClientSideSuspense } from '@liveblocks/react'
import { useThreads } from '../../../../liveblocks.config'
import { useDispatch } from '../../editor/store/dispatch-context'
import { switchEditorMode } from '../../editor/actions/action-creators'
import { canvasPoint } from '../../../core/shared/math-utils'
import { UtopiaTheme } from '../../../uuiui'
import { ErrorBoundary } from '../../../utils/react-error-boundary'
import { Substores, useEditorState } from '../../editor/store/store-hook'
import {
multiplayerColorFromIndex,
multiplayerInitialsFromName,
normalizeMultiplayerName,
} from '../../../core/shared/multiplayer'
import { MultiplayerWrapper } from '../../../utils/multiplayer-wrapper'

export const CommentIndicator = React.memo(() => {
const projectId = useEditorState(
Expand All @@ -31,9 +30,9 @@ export const CommentIndicator = React.memo(() => {

return (
<CanvasOffsetWrapper>
<ErrorBoundary fallback={null}>
<ClientSideSuspense fallback={null}>{() => <CommentIndicatorInner />}</ClientSideSuspense>
</ErrorBoundary>
<MultiplayerWrapper errorFallback={null} suspenseFallback={null}>
<CommentIndicatorInner />
</MultiplayerWrapper>
</CanvasOffsetWrapper>
)
})
Expand Down
14 changes: 7 additions & 7 deletions editor/src/components/canvas/controls/comment-popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ import React from 'react'
import { Substores, useEditorState } from '../../editor/store/store-hook'
import { CanvasOffsetWrapper } from './canvas-offset-wrapper'
import { isCommentMode } from '../../editor/editor-modes'
import { ClientSideSuspense } from '@liveblocks/react'
import { useCreateThread } from '../../../../liveblocks.config'
import type { ComposerSubmitComment } from '@liveblocks/react-comments'
import { Comment, Composer } from '@liveblocks/react-comments'
import { stopPropagation } from '../../inspector/common/inspector-utils'
import { UtopiaTheme } from '../../../uuiui'
import { ErrorBoundary } from '../../../utils/react-error-boundary'
import {
useCanvasCommentThread,
useMyMultiplayerColorIndex,
} from '../../../core/commenting/comment-hooks'
import { isLoggedIn } from '../../editor/action-types'
import { MultiplayerWrapper } from '../../../utils/multiplayer-wrapper'

export const CommentPopup = React.memo(() => {
const mode = useEditorState(
Expand Down Expand Up @@ -43,11 +42,12 @@ export const CommentPopup = React.memo(() => {
onKeyUp={stopPropagation}
onMouseUp={stopPropagation}
>
<ErrorBoundary fallback={<div>Can not load comments</div>}>
<ClientSideSuspense fallback={<div>Loading…</div>}>
{() => <CommentThread x={location.x} y={location.y} />}
</ClientSideSuspense>
</ErrorBoundary>
<MultiplayerWrapper
errorFallback={<div>Can not load comments</div>}
suspenseFallback={<div>Loading…</div>}
>
<CommentThread x={location.x} y={location.y} />
</MultiplayerWrapper>
</div>
</CanvasOffsetWrapper>
)
Expand Down
8 changes: 4 additions & 4 deletions editor/src/components/canvas/design-panel-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { FlexRow } from 'utopia-api'
import type { StoredPanel } from './stored-layout'
import { MultiplayerCursors } from './multiplayer-cursors'
import { useStatus } from '../../../liveblocks.config'
import { ClientSideSuspense } from '@liveblocks/react'
import { MultiplayerWrapper } from '../../utils/multiplayer-wrapper'

interface NumberSize {
width: number
Expand Down Expand Up @@ -146,9 +146,9 @@ const DesignPanelRootInner = React.memo(() => {
<CanvasWrapperComponent />
{when(
roomStatus === 'connected',
<ClientSideSuspense fallback={<div />}>
{() => <MultiplayerCursors />}
</ClientSideSuspense>,
<MultiplayerWrapper errorFallback={null} suspenseFallback={null}>
<MultiplayerCursors />
</MultiplayerWrapper>,
)}
<GridPanelsContainer />
</SimpleFlexColumn>
Expand Down
6 changes: 4 additions & 2 deletions editor/src/components/user-bar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ClientSideSuspense } from '@liveblocks/react'
import React from 'react'
import { useOthers, useSelf, useStatus } from '../../liveblocks.config'
import { getUserPicture, isLoggedIn } from '../common/user'
Expand All @@ -13,6 +12,7 @@ import {
import { Avatar, Tooltip, useColorTheme } from '../uuiui'
import { Substores, useEditorState } from './editor/store/store-hook'
import { unless, when } from '../utils/react-conditionals'
import { MultiplayerWrapper } from '../utils/multiplayer-wrapper'

const MAX_VISIBLE_OTHER_PLAYERS = 4

Expand All @@ -31,7 +31,9 @@ export const UserBar = React.memo(() => {
return <SinglePlayerUserBar />
} else {
return (
<ClientSideSuspense fallback={<div />}>{() => <MultiplayerUserBar />}</ClientSideSuspense>
<MultiplayerWrapper errorFallback={null} suspenseFallback={null}>
<MultiplayerUserBar />
</MultiplayerWrapper>
)
}
})
Expand Down
17 changes: 17 additions & 0 deletions editor/src/utils/multiplayer-wrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import { ErrorBoundary } from './react-error-boundary'
import { ClientSideSuspense } from '@liveblocks/react'

type Fallback = NonNullable<React.ReactNode> | null

export const MultiplayerWrapper = React.memo(
(props: { errorFallback: Fallback; suspenseFallback: Fallback; children: any }) => {
return (
<ErrorBoundary fallback={props.errorFallback}>
<ClientSideSuspense fallback={props.suspenseFallback}>
{() => props.children}
</ClientSideSuspense>
</ErrorBoundary>
)
},
)
Loading