Skip to content

Build your personal knowledge base with Trilium Notes

refactor(note_types): separate user templates into own method

Elian Doran9687a9d8ff3e
diff --git a/apps/client/src/services/froca.ts b/apps/client/src/services/froca.ts
index 131cec06f1..6bbc3a50dc 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<string>, silentNotFoundError = false): Promise<FNote[]> {
+ 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 b8d0578697..e9905063c4 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<string[]>("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<TreeCommandNames>[] = [
+ SEPARATOR
+ ];
+ for (const templateNote of templateNotes) {
+ items.push({
+ title: templateNote.title,
+ uiIcon: templateNote.getIcon(),
+ command: command,
+ type: templateNote.type,
+ templateNoteId: templateNote.noteId
+ });
+ }
return items;
}