Merge pull request #15861 from overleaf/ii-ide-page-prototype-review-panel-delete-thread

[web] React ide page delete thread

GitOrigin-RevId: 46e93d67d597a2277c771bda2a4837a871339224
This commit is contained in:
ilkin-overleaf 2023-11-24 16:29:10 +02:00 committed by Copybot
parent 6c1308e250
commit a75b44a6fc
5 changed files with 41 additions and 8 deletions

View file

@ -14,7 +14,7 @@ import { useConnectionContext } from '@/features/ide-react/context/connection-co
import { usePermissionsContext } from '@/features/ide-react/context/permissions-context'
import { debugConsole } from '@/utils/debugging'
import { useEditorContext } from '@/shared/context/editor-context'
import { getJSON, postJSON } from '@/infrastructure/fetch-json'
import { deleteJSON, getJSON, postJSON } from '@/infrastructure/fetch-json'
import ColorManager from '@/ide/colors/ColorManager'
// @ts-ignore
import RangesTracker from '@overleaf/ranges-tracker'
@ -869,8 +869,27 @@ function useReviewPanelState(): ReviewPanelStateReactIde {
[onCommentReopened, projectId]
)
const [deleteThread] =
useScopeValue<ReviewPanel.UpdaterFn<'deleteThread'>>('deleteThread')
const onThreadDeleted = useCallback((threadId: ThreadId) => {
setResolvedThreadIds(({ [threadId]: _, ...resolvedThreadIds }) => {
return resolvedThreadIds
})
setCommentThreads(({ [threadId]: _, ...commentThreads }) => {
return commentThreads
})
dispatchReviewPanelEvent('comment:remove', threadId)
}, [])
const deleteThread = useCallback(
(docId: DocId, threadId: ThreadId) => {
onThreadDeleted(threadId)
deleteJSON(`/project/${projectId}/doc/${docId}/thread/${threadId}`).catch(
debugConsole.error
)
sendMB('rp-comment-delete')
},
[onThreadDeleted, projectId]
)
const [refreshResolvedCommentsDropdown] = useScopeValue<
ReviewPanel.UpdaterFn<'refreshResolvedCommentsDropdown'>
>('refreshResolvedCommentsDropdown')
@ -962,6 +981,7 @@ function useReviewPanelState(): ReviewPanelStateReactIde {
])
useSocketListener(socket, 'reopen-thread', onCommentReopened)
useSocketListener(socket, 'delete-thread', onThreadDeleted)
const values = useMemo<ReviewPanelStateReactIde['values']>(
() => ({

View file

@ -18,7 +18,6 @@ export default function populateReviewPanelScope(store: ReactScopeValueStore) {
store.set('deleteComment', () => {})
store.set('gotoEntry', () => {})
store.set('saveEdit', () => {})
store.set('deleteThread', () => {})
store.set('refreshResolvedCommentsDropdown', async () => {})
store.set('acceptChanges', () => {})
store.set('rejectChanges', () => {})

View file

@ -42,7 +42,7 @@ function ResolvedCommentEntry({
}
const handleDelete = () => {
deleteThread(undefined, thread.docId, thread.threadId)
deleteThread(thread.docId, thread.threadId)
}
return (

View file

@ -7,6 +7,7 @@ import {
SubView,
ThreadId,
} from '../../../../../../../types/review-panel/review-panel'
import { DocId } from '../../../../../../../types/project-settings'
import { dispatchReviewPanelLayout as handleLayoutChange } from '../../../extensions/changes/change-manager'
function useAngularReviewPanelState(): ReviewPanelState {
@ -99,8 +100,21 @@ function useAngularReviewPanelState(): ReviewPanelState {
)
const [unresolveComment] =
useScopeValue<ReviewPanel.UpdaterFn<'unresolveComment'>>('unresolveComment')
const [deleteThread] =
useScopeValue<ReviewPanel.UpdaterFn<'deleteThread'>>('deleteThread')
const [deleteThreadAngular] =
useScopeValue<
(
_: unknown,
...args: [...Parameters<ReviewPanel.UpdaterFn<'deleteThread'>>]
) => ReturnType<ReviewPanel.UpdaterFn<'deleteThread'>>
>('deleteThread')
const deleteThread = useCallback(
(docId: DocId, threadId: ThreadId) => {
deleteThreadAngular(undefined, docId, threadId)
},
[deleteThreadAngular]
)
const [refreshResolvedCommentsDropdown] = useScopeValue<
ReviewPanel.UpdaterFn<'refreshResolvedCommentsDropdown'>
>('refreshResolvedCommentsDropdown')

View file

@ -71,7 +71,7 @@ export interface ReviewPanelState {
content: string
) => void
unresolveComment: (threadId: ThreadId) => void
deleteThread: (_entryId: unknown, docId: DocId, threadId: ThreadId) => void
deleteThread: (docId: DocId, threadId: ThreadId) => void
refreshResolvedCommentsDropdown: () => Promise<void>
submitNewComment: (content: string) => Promise<void>
setEntryHover: React.Dispatch<React.SetStateAction<Value<'entryHover'>>>