Update modified tracked changes in the React state (#20877)

GitOrigin-RevId: d3b17908aa43d99b6e46550f2de77186f9d7b86d
This commit is contained in:
Alf Eaton 2024-10-10 13:50:08 +01:00 committed by Copybot
parent ee2e95ec01
commit 9ba6a6a042

View file

@ -32,13 +32,24 @@ type RangesActions = {
} }
const buildRanges = (currentDoc: DocumentContainer | null) => { const buildRanges = (currentDoc: DocumentContainer | null) => {
if (currentDoc?.ranges) { const ranges = currentDoc?.ranges
return {
...currentDoc.ranges, if (!ranges) {
docId: currentDoc.doc_id, return undefined
total: }
currentDoc.ranges.changes.length + currentDoc.ranges.comments.length,
} const dirtyState = ranges.getDirtyState()
ranges.resetDirtyState()
return {
changes: ranges.changes.map(change =>
change.id in dirtyState.change ? { ...change } : change
),
comments: ranges.comments.map(comment =>
comment.id in dirtyState.comment ? { ...comment } : comment
),
docId: currentDoc.doc_id,
total: ranges.changes.length + ranges.comments.length,
} }
} }