fix(collections): not updating on import

This commit is contained in:
Elian Doran
2025-09-13 14:42:02 +03:00
parent 9c8b0611ea
commit 050ff5d8cd
2 changed files with 25 additions and 2 deletions

View File

@@ -9,6 +9,8 @@ import ViewModeStorage from "../view_widgets/view_mode_storage";
import CalendarView from "./calendar";
import TableView from "./table";
import BoardView from "./board";
import { subscribeToMessages, unsubscribeToMessage as unsubscribeFromMessage } from "../../services/ws";
import { WebSocketMessage } from "@triliumnext/commons";
interface NoteListProps<T extends object> {
note?: FNote | null;
@@ -137,6 +139,23 @@ function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOptions |
}
})
// Refresh on import.
useEffect(() => {
function onImport(message: WebSocketMessage) {
if (!("taskType" in message) || message.taskType !== "importNotes" || message.type !== "taskSucceeded") return;
const { parentNoteId, importedNoteId } = message.result;
if (parentNoteId && importedNoteId && (parentNoteId === note?.noteId || noteIds.includes(parentNoteId))) {
setNoteIds([
...noteIds,
importedNoteId
])
}
}
subscribeToMessages(onImport);
return () => unsubscribeFromMessage(onImport);
}, [ note, noteIds, setNoteIds ])
return noteIds;
}