Skip to content

Commit

Permalink
Fix thread with first comment deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
gbalint committed Jan 3, 2024
1 parent 5a967bf commit 69fa020
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion editor/src/components/canvas/controls/comment-indicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
windowPoint,
} from '../../../core/shared/math-utils'
import {
getFirstComment,
multiplayerColorFromIndex,
multiplayerInitialsFromName,
normalizeMultiplayerName,
Expand Down Expand Up @@ -427,7 +428,7 @@ const HoveredCommentIndicator = React.memo((props: HoveredCommentIndicatorProps)
return null
}

const comment = thread.comments[0]
const comment = getFirstComment(thread)
if (comment == null) {
return null
}
Expand Down
5 changes: 3 additions & 2 deletions editor/src/components/inspector/sections/comment-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
} from '../../../core/commenting/comment-hooks'
import { Substores, useEditorState, useSelectorWithCallback } from '../../editor/store/store-hook'
import { when } from '../../../utils/react-conditionals'
import { openCommentThreadActions } from '../../../core/shared/multiplayer'
import { getFirstComment, openCommentThreadActions } from '../../../core/shared/multiplayer'
import { getRemixLocationLabel } from '../../canvas/remix/remix-utils'
import type { RestOfEditorState } from '../../editor/store/store-hook-substore-types'
import { getCurrentTheme } from '../../editor/store/editor-state'
Expand Down Expand Up @@ -215,7 +215,8 @@ const ThreadPreview = React.memo(({ thread }: ThreadPreviewProps) => {
'ThreadPreview theme',
)

const comment = thread.comments[0]
const comment = getFirstComment(thread)

if (comment == null) {
return null
}
Expand Down
8 changes: 6 additions & 2 deletions editor/src/core/shared/multiplayer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { User } from '@liveblocks/client'
import type { Presence, UserMeta } from '../../../liveblocks.config'
import type { CommentData, ThreadData, User } from '@liveblocks/client'
import type { Presence, ThreadMetadata, UserMeta } from '../../../liveblocks.config'
import { possiblyUniqueInArray, safeIndex, stripNulls, uniqBy } from './array-utils'
import { colorTheme, getPreferredColorScheme } from '../../uuiui'
import type { ElementPath } from './project-file-types'
Expand Down Expand Up @@ -161,3 +161,7 @@ export function openCommentThreadActions(threadId: string, scene: ElementPath |
scene != null ? setHighlightedView(scene) : null,
])
}

export function getFirstComment(thread: ThreadData<ThreadMetadata>): CommentData | null {
return thread.comments.filter((c) => c.deletedAt == null)[0] ?? null
}

0 comments on commit 69fa020

Please sign in to comment.