Skip to content

Commit

Permalink
Extract hook
Browse files Browse the repository at this point in the history
  • Loading branch information
gbalint committed Nov 20, 2023
1 parent 0c094ae commit 35dbd20
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions editor/src/components/user-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useDispatch } from './editor/store/dispatch-context'
import { switchEditorMode } from './editor/actions/action-creators'
import type { EditorAction } from './editor/action-types'
import { EditorModes, isFollowMode } from './editor/editor-modes'
import { useMyUserAndPresence } from '../core/commenting/comment-hooks'

const MAX_VISIBLE_OTHER_PLAYERS = 4

Expand Down Expand Up @@ -61,12 +62,11 @@ const MultiplayerUserBar = React.memo(() => {
const dispatch = useDispatch()
const colorTheme = useColorTheme()

const me = useSelf()
const myUser = useStorage((store) => store.collaborators[me.id])
const { user: myUser } = useMyUserAndPresence()
const myName = normalizeMultiplayerName(myUser.name)

const others = useOthers((list) =>
normalizeOthersList(me.id, list).map((other) => ({
normalizeOthersList(myUser.id, list).map((other) => ({
id: other.id,
name: myUser.name,
colorIndex: myUser.colorIndex,
Expand Down
12 changes: 10 additions & 2 deletions editor/src/core/commenting/comment-hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ export function useCanvasCommentThread(x: number, y: number): ThreadData<ThreadM
return thread
}

export function useMyMultiplayerColorIndex() {
export function useMyUserAndPresence() {
const me = useSelf()
const myUser = useStorage((store) => store.collaborators[me.id])
return myUser.colorIndex
return {
presence: me,
user: myUser,
}
}

export function useMyMultiplayerColorIndex() {
const me = useMyUserAndPresence()
return me.user.colorIndex
}

export function useAddMyselfToCollaborators() {
Expand Down

0 comments on commit 35dbd20

Please sign in to comment.