refactor: fix conflicts view when conflicted copies are already in trash (#2339)

This commit is contained in:
Aman Harwara
2023-06-27 22:08:46 +05:30
committed by GitHub
parent f858f31492
commit d3378a704a
7 changed files with 102 additions and 35 deletions

View File

@@ -432,36 +432,11 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
this.debounceReloadEditorComponent()
})
this.removeNoteStreamObserver = this.application.streamItems<SNNote>(
ContentType.Note,
async ({ inserted, changed, removed }) => {
const insertedOrChanged = inserted.concat(changed)
for (const note of insertedOrChanged) {
if (note.conflictOf === this.note.uuid && !note.trashed) {
this.setState((state) => ({
conflictedNotes: state.conflictedNotes
.filter((conflictedNote) => conflictedNote.uuid !== note.uuid)
.concat([note]),
}))
} else {
this.setState((state) => {
return {
conflictedNotes: state.conflictedNotes.filter((conflictedNote) => conflictedNote.uuid !== note.uuid),
}
})
}
}
for (const note of removed) {
this.setState((state) => {
return {
conflictedNotes: state.conflictedNotes.filter((conflictedNote) => conflictedNote.uuid !== note.uuid),
}
})
}
},
)
this.removeNoteStreamObserver = this.application.streamItems<SNNote>(ContentType.Note, async () => {
this.setState({
conflictedNotes: this.application.items.conflictsOf(this.note.uuid) as SNNote[],
})
})
}
private createComponentViewer(component: SNComponent) {