mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
Use thread id in removeNewCommentRangeEffect (#23205)
GitOrigin-RevId: 6082f5e6d6f548eff43da657526097118a2d3c11
This commit is contained in:
+8
-9
@@ -1,4 +1,4 @@
|
|||||||
import { FC, FormEventHandler, useCallback, useState, useRef } from 'react'
|
import { FormEventHandler, useCallback, useState, useRef, memo } from 'react'
|
||||||
import {
|
import {
|
||||||
useCodeMirrorStateContext,
|
useCodeMirrorStateContext,
|
||||||
useCodeMirrorViewContext,
|
useCodeMirrorViewContext,
|
||||||
@@ -11,18 +11,17 @@ import useSubmittableTextInput from '../hooks/use-submittable-text-input'
|
|||||||
import AutoExpandingTextArea from '@/shared/components/auto-expanding-text-area'
|
import AutoExpandingTextArea from '@/shared/components/auto-expanding-text-area'
|
||||||
import { ReviewPanelEntry } from './review-panel-entry'
|
import { ReviewPanelEntry } from './review-panel-entry'
|
||||||
import { ThreadId } from '../../../../../types/review-panel/review-panel'
|
import { ThreadId } from '../../../../../types/review-panel/review-panel'
|
||||||
import { Decoration } from '@codemirror/view'
|
|
||||||
import { useModalsContext } from '@/features/ide-react/context/modals-context'
|
import { useModalsContext } from '@/features/ide-react/context/modals-context'
|
||||||
import { debugConsole } from '@/utils/debugging'
|
import { debugConsole } from '@/utils/debugging'
|
||||||
import OLButton from '@/features/ui/components/ol/ol-button'
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
||||||
|
|
||||||
export const ReviewPanelAddComment: FC<{
|
export const ReviewPanelAddComment = memo<{
|
||||||
docId: string
|
docId: string
|
||||||
from: number
|
from: number
|
||||||
to: number
|
to: number
|
||||||
value: Decoration
|
threadId: string
|
||||||
top: number | undefined
|
top: number | undefined
|
||||||
}> = ({ from, to, value, top, docId }) => {
|
}>(function ReviewPanelAddComment({ from, to, threadId, top, docId }) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const view = useCodeMirrorViewContext()
|
const view = useCodeMirrorViewContext()
|
||||||
const state = useCodeMirrorStateContext()
|
const state = useCodeMirrorStateContext()
|
||||||
@@ -32,9 +31,9 @@ export const ReviewPanelAddComment: FC<{
|
|||||||
|
|
||||||
const handleClose = useCallback(() => {
|
const handleClose = useCallback(() => {
|
||||||
view.dispatch({
|
view.dispatch({
|
||||||
effects: removeNewCommentRangeEffect.of(value),
|
effects: removeNewCommentRangeEffect.of(threadId),
|
||||||
})
|
})
|
||||||
}, [view, value])
|
}, [view, threadId])
|
||||||
|
|
||||||
const submitForm = useCallback(
|
const submitForm = useCallback(
|
||||||
async message => {
|
async message => {
|
||||||
@@ -127,7 +126,7 @@ export const ReviewPanelAddComment: FC<{
|
|||||||
op={{
|
op={{
|
||||||
p: from,
|
p: from,
|
||||||
c: state.sliceDoc(from, to),
|
c: state.sliceDoc(from, to),
|
||||||
t: value.spec.id as ThreadId,
|
t: threadId as ThreadId,
|
||||||
}}
|
}}
|
||||||
selectLineOnFocus={false}
|
selectLineOnFocus={false}
|
||||||
disabled={submitting}
|
disabled={submitting}
|
||||||
@@ -169,4 +168,4 @@ export const ReviewPanelAddComment: FC<{
|
|||||||
</form>
|
</form>
|
||||||
</ReviewPanelEntry>
|
</ReviewPanelEntry>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
|
|||||||
+4
-4
@@ -201,13 +201,13 @@ const ReviewPanelCurrentFile: FC = () => {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const { from, to } = cursor
|
const { from, to, value } = cursor
|
||||||
|
|
||||||
entries.push({
|
entries.push({
|
||||||
id,
|
id,
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
value: cursor.value,
|
threadId: value.spec.id,
|
||||||
top: positions.get(id),
|
top: positions.get(id),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -297,14 +297,14 @@ const ReviewPanelCurrentFile: FC = () => {
|
|||||||
|
|
||||||
<div ref={handleContainer}>
|
<div ref={handleContainer}>
|
||||||
{addCommentEntries.map(entry => {
|
{addCommentEntries.map(entry => {
|
||||||
const { id, from, to, value, top } = entry
|
const { id, from, to, threadId, top } = entry
|
||||||
return (
|
return (
|
||||||
<ReviewPanelAddComment
|
<ReviewPanelAddComment
|
||||||
docId={ranges!.docId}
|
docId={ranges!.docId}
|
||||||
key={id}
|
key={id}
|
||||||
from={from}
|
from={from}
|
||||||
to={to}
|
to={to}
|
||||||
value={value}
|
threadId={threadId}
|
||||||
top={top}
|
top={top}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import { v4 as uuid } from 'uuid'
|
|||||||
|
|
||||||
export const addNewCommentRangeEffect = StateEffect.define<Range<Decoration>>()
|
export const addNewCommentRangeEffect = StateEffect.define<Range<Decoration>>()
|
||||||
|
|
||||||
export const removeNewCommentRangeEffect = StateEffect.define<Decoration>()
|
export const removeNewCommentRangeEffect = StateEffect.define<string>()
|
||||||
|
|
||||||
export const textSelectedEffect = StateEffect.define<null>()
|
export const textSelectedEffect = StateEffect.define<null>()
|
||||||
|
|
||||||
@@ -103,11 +103,10 @@ export const reviewTooltipStateField = StateField.define<{
|
|||||||
|
|
||||||
for (const effect of tr.effects) {
|
for (const effect of tr.effects) {
|
||||||
if (effect.is(removeNewCommentRangeEffect)) {
|
if (effect.is(removeNewCommentRangeEffect)) {
|
||||||
const rangeToRemove = effect.value
|
const threadId = effect.value
|
||||||
addCommentRanges = addCommentRanges.update({
|
addCommentRanges = addCommentRanges.update({
|
||||||
// eslint-disable-next-line no-unused-vars
|
filter: (_from, _to, value) => {
|
||||||
filter: (from, to, value) => {
|
return value.spec.id !== threadId
|
||||||
return value.spec.id !== rangeToRemove.spec.id
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user