refactor(note_types): separate user templates into own method

This commit is contained in:
Elian Doran 2025-06-17 18:39:37 +03:00
parent fa11295693
commit 9687a9d8ff
No known key found for this signature in database
2 changed files with 24 additions and 14 deletions

View File

@ -245,6 +245,10 @@ class FrocaImpl implements Froca {
} }
async getNotes(noteIds: string[] | JQuery<string>, silentNotFoundError = false): Promise<FNote[]> { async getNotes(noteIds: string[] | JQuery<string>, silentNotFoundError = false): Promise<FNote[]> {
if (noteIds.length === 0) {
return [];
}
noteIds = Array.from(new Set(noteIds)); // make unique noteIds = Array.from(new Set(noteIds)); // make unique
const missingNoteIds = noteIds.filter((noteId) => !this.notes[noteId]); const missingNoteIds = noteIds.filter((noteId) => !this.notes[noteId]);

View File

@ -20,15 +20,23 @@ async function getNoteTypeItems(command?: TreeCommandNames) {
{ title: t("note_types.web-view"), command, type: "webView", uiIcon: "bx bx-globe-alt" }, { 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.mind-map"), command, type: "mindMap", uiIcon: "bx bx-sitemap" },
{ title: t("note_types.geo-map"), command, type: "geoMap", uiIcon: "bx bx-map-alt" }, { 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 templateNoteIds = await server.get<string[]>("search-templates");
const templateNotes = await froca.getNotes(templateNoteIds); const templateNotes = await froca.getNotes(templateNoteIds);
if (templateNotes.length === 0) {
return [];
}
if (templateNotes.length > 0) { const items: MenuItem<TreeCommandNames>[] = [
items.push({ title: "----" }); SEPARATOR
];
for (const templateNote of templateNotes) { for (const templateNote of templateNotes) {
items.push({ items.push({
title: templateNote.title, title: templateNote.title,
@ -38,8 +46,6 @@ async function getNoteTypeItems(command?: TreeCommandNames) {
templateNoteId: templateNote.noteId templateNoteId: templateNote.noteId
}); });
} }
}
return items; return items;
} }