chore(collections): support child notes on import as well

This commit is contained in:
Elian Doran
2025-09-13 14:47:40 +03:00
parent 050ff5d8cd
commit 6ba494999c

View File

@@ -11,6 +11,7 @@ import TableView from "./table";
import BoardView from "./board";
import { subscribeToMessages, unsubscribeToMessage as unsubscribeFromMessage } from "../../services/ws";
import { WebSocketMessage } from "@triliumnext/commons";
import froca from "../../services/froca";
interface NoteListProps<T extends object> {
note?: FNote | null;
@@ -116,12 +117,17 @@ function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOptions |
async function refreshNoteIds() {
if (!note) {
setNoteIds([]);
} else if (viewType === "list" || viewType === "grid") {
console.log("Refreshed note IDs");
setNoteIds(note.getChildNoteIds());
} else {
setNoteIds(await getNoteIds(note));
}
}
async function getNoteIds(note: FNote) {
console.log("Refreshed note IDs");
setNoteIds(await note.getSubtreeNoteIds(includeArchived));
if (viewType === "list" || viewType === "grid") {
return note.getChildNoteIds();
} else {
return await note.getSubtreeNoteIds(includeArchived);
}
}
@@ -141,12 +147,16 @@ function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOptions |
// Refresh on import.
useEffect(() => {
function onImport(message: WebSocketMessage) {
async 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))) {
if (!parentNoteId || !importedNoteId) return;
if (importedNoteId && (parentNoteId === note?.noteId || noteIds.includes(parentNoteId))) {
const importedNote = await froca.getNote(importedNoteId);
if (!importedNote) return;
setNoteIds([
...noteIds,
...await getNoteIds(importedNote),
importedNoteId
])
}