Merge pull request #15944 from overleaf/ii-ide-page-prototype-review-panel-resolve-comment

[web] React ide page resolve comment

GitOrigin-RevId: a55dfd2972bfb94c0e10465f3588be419477e1da
This commit is contained in:
ilkin-overleaf 2023-11-27 13:28:23 +02:00 committed by Copybot
parent 35a0501276
commit 9821498a00
2 changed files with 49 additions and 9 deletions

View file

@ -47,6 +47,7 @@ import {
ReviewPanelCommentThreadsApi,
} from '../../../../../../../types/review-panel/api'
import { Document } from '@/features/ide-react/editor/document'
import { DateString } from '../../../../../../../types/helpers/date'
const dispatchReviewPanelEvent = (type: string, payload?: any) => {
window.dispatchEvent(
@ -816,8 +817,6 @@ function useReviewPanelState(): ReviewPanelStateReactIde {
applyTrackChangesStateToClient
)
const [resolveComment] =
useScopeValue<ReviewPanel.UpdaterFn<'resolveComment'>>('resolveComment')
const [submitNewComment] =
useScopeValue<ReviewPanel.UpdaterFn<'submitNewComment'>>('submitNewComment')
const [deleteComment] =
@ -841,6 +840,53 @@ function useReviewPanelState(): ReviewPanelStateReactIde {
})
}, [reviewPanelOpen, setReviewPanelOpen, trackChangesVisible])
const onCommentResolved = useCallback(
(threadId: ThreadId, user: any) => {
setCommentThreads(prevState => {
const thread = { ...getThread(threadId) }
thread.resolved = true
thread.resolved_by_user = formatUser(user)
thread.resolved_at = new Date().toISOString() as DateString
return { ...prevState, [threadId]: thread }
})
setResolvedThreadIds(prevState => ({ ...prevState, [threadId]: true }))
dispatchReviewPanelEvent('comment:resolve_threads', [threadId])
},
[getThread]
)
const resolveComment = useCallback(
(docId: DocId, entryId: ThreadId) => {
const docEntries = getDocEntries(docId)
const entry = docEntries[entryId] as ReviewPanelCommentEntry
setEntries(prevState => ({
...prevState,
[docId]: {
...prevState[docId],
[entryId]: {
...prevState[docId][entryId],
focused: false,
},
},
}))
postJSON(`/project/${projectId}/thread/${entry.thread_id}/resolve`)
onCommentResolved(entry.thread_id, user)
sendMB('rp-comment-resolve', {
view: reviewPanelOpen ? subView : 'mini',
})
},
[
getDocEntries,
onCommentResolved,
projectId,
reviewPanelOpen,
subView,
user,
]
)
const onCommentReopened = useCallback(
(threadId: ThreadId) => {
setCommentThreads(prevState => {
@ -1021,6 +1067,7 @@ function useReviewPanelState(): ReviewPanelStateReactIde {
useSocketListener(socket, 'reopen-thread', onCommentReopened)
useSocketListener(socket, 'delete-thread', onThreadDeleted)
useSocketListener(socket, 'resolve-thread', onCommentResolved)
const values = useMemo<ReviewPanelStateReactIde['values']>(
() => ({

View file

@ -3,16 +3,9 @@ import { ReactScopeValueStore } from '@/features/ide-react/scope-value-store/rea
export default function populateReviewPanelScope(store: ReactScopeValueStore) {
store.set('reviewPanel.overview.loading', false)
store.set('reviewPanel.nVisibleSelectedChanges', 0)
store.set('permissions', {
read: false,
write: false,
admin: false,
comment: false,
})
store.set('users', {})
store.set('reviewPanel.layoutToLeft', false)
store.set('reviewPanel.rendererData.lineHeight', 0)
store.set('resolveComment', () => {})
store.set('submitNewComment', async () => {})
store.set('deleteComment', () => {})
store.set('gotoEntry', () => {})