diff --git a/apps/client/src/services/froca.ts b/apps/client/src/services/froca.ts index 131cec06f..6bbc3a50d 100644 --- a/apps/client/src/services/froca.ts +++ b/apps/client/src/services/froca.ts @@ -245,6 +245,10 @@ class FrocaImpl implements Froca { } async getNotes(noteIds: string[] | JQuery, silentNotFoundError = false): Promise { + if (noteIds.length === 0) { + return []; + } + noteIds = Array.from(new Set(noteIds)); // make unique const missingNoteIds = noteIds.filter((noteId) => !this.notes[noteId]); diff --git a/apps/client/src/services/note_types.ts b/apps/client/src/services/note_types.ts index b8d057869..e9905063c 100644 --- a/apps/client/src/services/note_types.ts +++ b/apps/client/src/services/note_types.ts @@ -20,26 +20,32 @@ async function getNoteTypeItems(command?: TreeCommandNames) { { title: t("note_types.web-view"), command, type: "webView", uiIcon: "bx bx-globe-alt" }, { title: t("note_types.mind-map"), command, type: "mindMap", uiIcon: "bx bx-sitemap" }, { title: t("note_types.geo-map"), command, type: "geoMap", uiIcon: "bx bx-map-alt" }, - ...await getBuiltInTemplates(command) + ...await getBuiltInTemplates(command), + ...await getUserTemplates(command) ]; + return items; +} + +async function getUserTemplates(command?: TreeCommandNames) { const templateNoteIds = await server.get("search-templates"); const templateNotes = await froca.getNotes(templateNoteIds); - - if (templateNotes.length > 0) { - items.push({ title: "----" }); - - for (const templateNote of templateNotes) { - items.push({ - title: templateNote.title, - uiIcon: templateNote.getIcon(), - command: command, - type: templateNote.type, - templateNoteId: templateNote.noteId - }); - } + if (templateNotes.length === 0) { + return []; } + const items: MenuItem[] = [ + SEPARATOR + ]; + for (const templateNote of templateNotes) { + items.push({ + title: templateNote.title, + uiIcon: templateNote.getIcon(), + command: command, + type: templateNote.type, + templateNoteId: templateNote.noteId + }); + } return items; }