mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-04 14:49:01 +02:00
Add "accept-changes" socket listener in ranges context (#22048)
GitOrigin-RevId: 0be5f3be1806aad29f44eec2e596af51e65263e7
This commit is contained in:
committed by
Copybot
parent
cb60dbbb87
commit
2226cfd233
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
createContext,
|
||||
FC,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
@@ -18,6 +19,8 @@ import { rejectChanges } from '@/features/source-editor/extensions/changes/rejec
|
||||
import { useCodeMirrorViewContext } from '@/features/source-editor/components/codemirror-context'
|
||||
import { postJSON } from '@/infrastructure/fetch-json'
|
||||
import { useIdeReactContext } from '@/features/ide-react/context/ide-react-context'
|
||||
import { useConnectionContext } from '@/features/ide-react/context/connection-context'
|
||||
import useSocketListener from '@/features/ide-react/hooks/use-socket-listener'
|
||||
|
||||
export type Ranges = {
|
||||
docId: string
|
||||
@@ -82,7 +85,7 @@ export const RangesProvider: FC = ({ children }) => {
|
||||
const [currentDoc] = useScopeValue<DocumentContainer | null>(
|
||||
'editor.sharejs_doc'
|
||||
)
|
||||
|
||||
const { socket } = useConnectionContext()
|
||||
const [ranges, setRanges] = useState<Ranges | undefined>(() =>
|
||||
buildRanges(currentDoc)
|
||||
)
|
||||
@@ -134,6 +137,22 @@ export const RangesProvider: FC = ({ children }) => {
|
||||
}
|
||||
}, [currentDoc])
|
||||
|
||||
useSocketListener(
|
||||
socket,
|
||||
'accept-changes',
|
||||
useCallback(
|
||||
(docId: string, entryIds: string[]) => {
|
||||
if (currentDoc?.ranges) {
|
||||
if (docId === currentDoc.doc_id) {
|
||||
currentDoc.ranges.removeChangeIds(entryIds)
|
||||
setRanges(buildRanges(currentDoc))
|
||||
}
|
||||
}
|
||||
},
|
||||
[currentDoc]
|
||||
)
|
||||
)
|
||||
|
||||
const actions = useMemo(
|
||||
() => ({
|
||||
async acceptChanges(...ids: string[]) {
|
||||
|
||||
Reference in New Issue
Block a user