Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(client/ts): use context_menu in note_type_chooser
Elian Doran10f8da801507
diff --git a/src/public/app/services/note_types.ts b/src/public/app/services/note_types.tsindex 472004dab8..cb491b4c49 100644--- a/src/public/app/services/note_types.ts+++ b/src/public/app/services/note_types.ts@@ -1,23 +1,10 @@import server from "./server.js";import froca from "./froca.js";import { t } from "./i18n.js";--interface NoteTypeSeparator {- title: "----"-}--export interface NoteType {- title: string;- command?: string;- type: string;- uiIcon: string;- templateNoteId?: string;-}--type NoteTypeItem = NoteType | NoteTypeSeparator;+import { MenuItem } from "../menus/context_menu.js";async function getNoteTypeItems(command?: string) {- const items: NoteTypeItem[] = [+ const items: MenuItem[] = [{ title: t("note_types.text"), command: command, type: "text", uiIcon: "bx bx-note" },{ title: t("note_types.code"), command: command, type: "code", uiIcon: "bx bx-code" },{ title: t("note_types.saved-search"), command: command, type: "search", uiIcon: "bx bx-file-find" },diff --git a/src/public/app/widgets/dialogs/note_type_chooser.ts b/src/public/app/widgets/dialogs/note_type_chooser.tsindex 57995e3154..6af7c4e3bd 100644--- a/src/public/app/widgets/dialogs/note_type_chooser.ts+++ b/src/public/app/widgets/dialogs/note_type_chooser.ts@@ -1,5 +1,6 @@+import { MenuCommandItem } from "../../menus/context_menu.js";import { t } from "../../services/i18n.js";-import noteTypesService, { NoteType } from "../../services/note_types.js";+import noteTypesService from "../../services/note_types.js";import BasicWidget from "../basic_widget.js";const TPL = `@@ -9,7 +10,7 @@ const TPL = `/* note type chooser needs to be higher than other dialogs from which it is triggered, e.g. "add link"*/z-index: 1100 !important;}-+.note-type-chooser-dialog .note-type-dropdown {position: relative;font-size: large;@@ -67,7 +68,7 @@ export default class NoteTypeChooserDialog extends BasicWidget {}doRender() {- this.$widget = $(TPL);+ this.$widget = $(TPL);// TODO: Remove once we import bootstrap the right way//@ts-ignorethis.modal = bootstrap.Modal.getOrCreateInstance(this.$widget);@@ -126,12 +127,13 @@ export default class NoteTypeChooserDialog extends BasicWidget {for (const noteType of noteTypes) {if (noteType.title === '----') {this.$noteTypeDropdown.append($('<h6 class="dropdown-header">').append(t("note_type_chooser.templates")));- } else {+ } else {+ const commandItem = (noteType as MenuCommandItem)this.$noteTypeDropdown.append($('<a class="dropdown-item" tabindex="0">')- .attr("data-note-type", (noteType as NoteType).type)- .attr("data-template-note-id", (noteType as NoteType).templateNoteId || "")- .append($("<span>").addClass((noteType as NoteType).uiIcon))+ .attr("data-note-type", commandItem.type)+ .attr("data-template-note-id", commandItem.templateNoteId || "")+ .append($("<span>").addClass(commandItem.uiIcon)).append(` ${noteType.title}`));}