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

Sort threads by last update in comment section #4687

Merged
merged 1 commit into from
Jan 4, 2024
Merged
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
9 changes: 8 additions & 1 deletion editor/src/components/inspector/sections/comment-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ import {
} from '../../../core/commenting/comment-hooks'
import { Substores, useEditorState, useSelectorWithCallback } from '../../editor/store/store-hook'
import { when } from '../../../utils/react-conditionals'
import { getFirstComment, openCommentThreadActions } from '../../../core/shared/multiplayer'
import {
getFirstComment,
openCommentThreadActions,
sortThreadsByDescendingUpdateTimeInPlace,
} 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 @@ -73,6 +77,9 @@ const ThreadPreviews = React.memo(() => {
const { threads: activeThreads } = useUnresolvedThreads()
const { threads: resolvedThreads } = useResolvedThreads()

sortThreadsByDescendingUpdateTimeInPlace(activeThreads)
sortThreadsByDescendingUpdateTimeInPlace(resolvedThreads)

const showResolved = useEditorState(
Substores.restOfEditor,
(store) => store.editor.showResolvedThreads,
Expand Down
10 changes: 10 additions & 0 deletions editor/src/core/shared/multiplayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,13 @@ export function openCommentThreadActions(threadId: string, scene: ElementPath |
export function getFirstComment(thread: ThreadData<ThreadMetadata>): CommentData | null {
return thread.comments.filter((c) => c.deletedAt == null)[0] ?? null
}

export function sortThreadsByDescendingUpdateTimeInPlace(
threads: Array<ThreadData<ThreadMetadata>>,
) {
function lastModificationDate(t: ThreadData<ThreadMetadata>) {
return t.updatedAt ?? t.createdAt
}

threads.sort((t1, t2) => lastModificationDate(t2).getTime() - lastModificationDate(t1).getTime())
}
Loading