diff --git a/apps/server/src/becca/entities/bnote.ts b/apps/server/src/becca/entities/bnote.ts index 7f271e88c..e67d8928b 100644 --- a/apps/server/src/becca/entities/bnote.ts +++ b/apps/server/src/becca/entities/bnote.ts @@ -1,5 +1,5 @@ import type { AttachmentRow, AttributeType, CloneResponse, NoteRow, NoteType, RevisionRow } from "@triliumnext/commons"; -import { dayjs } from "@triliumnext/commons"; +import { dayjs, getNoteIcon } from "@triliumnext/commons"; import cloningService from "../../services/cloning.js"; import dateUtils from "../../services/date_utils.js"; @@ -24,26 +24,6 @@ import BRevision from "./brevision.js"; const LABEL = "label"; const RELATION = "relation"; -// TODO: Deduplicate with fnote -export const NOTE_TYPE_ICONS = { - file: "bx bx-file", - image: "bx bx-image", - code: "bx bx-code", - render: "bx bx-extension", - search: "bx bx-file-find", - relationMap: "bx bxs-network-chart", - book: "bx bx-book", - noteMap: "bx bxs-network-chart", - mermaid: "bx bx-selection", - canvas: "bx bx-pen", - webView: "bx bx-globe-alt", - launcher: "bx bx-link", - doc: "bx bxs-file-doc", - contentWidget: "bx bxs-widget", - mindMap: "bx bx-sitemap", - geoMap: "bx bx-map-alt" -}; - interface NotePathRecord { isArchived: boolean; isInHoistedSubTree: boolean; @@ -1698,30 +1678,17 @@ class BNote extends AbstractBeccaEntity { } getIcon() { - return `tn-icon ${this.#getIconInternal()}`; - } - - // TODO: Deduplicate with fnote - #getIconInternal() { const iconClassLabels = this.getLabels("iconClass"); + const icon = getNoteIcon({ + noteId: this.noteId, + type: this.type, + mime: this.mime, + iconClass: iconClassLabels.length > 0 ? iconClassLabels[0].value : undefined, + workspaceIconClass: undefined, + isFolder: this.isFolder.bind(this) + }); - if (iconClassLabels && iconClassLabels.length > 0) { - return iconClassLabels[0].value; - } else if (this.noteId === "root") { - return "bx bx-home-alt-2"; - } - if (this.noteId === "_share") { - return "bx bx-share-alt"; - } else if (this.type === "text") { - if (this.isFolder()) { - return "bx bx-folder"; - } - return "bx bx-note"; - - } else if (this.type === "code" && this.mime.startsWith("text/x-sql")) { - return "bx bx-data"; - } - return NOTE_TYPE_ICONS[this.type]; + return `tn-icon ${icon}`; } // TODO: Deduplicate with fnote diff --git a/apps/server/src/share/shaca/entities/snote.ts b/apps/server/src/share/shaca/entities/snote.ts index da72cd419..852c2b890 100644 --- a/apps/server/src/share/shaca/entities/snote.ts +++ b/apps/server/src/share/shaca/entities/snote.ts @@ -1,6 +1,6 @@ +import { getNoteIcon, NoteType } from "@triliumnext/commons"; import escape from "escape-html"; -import { NOTE_TYPE_ICONS } from "../../../becca/entities/bnote.js"; import type { Blob } from "../../../services/blob-interface.js"; import utils from "../../../services/utils.js"; import sql from "../../sql.js"; @@ -19,7 +19,7 @@ const isCredentials = (attr: SAttribute) => attr.type === "label" && attr.name = class SNote extends AbstractShacaEntity { noteId: string; title: string; - type: string; + type: NoteType; mime: string; private blobId: string; utcDateModified: string; @@ -38,7 +38,7 @@ class SNote extends AbstractShacaEntity { this.noteId = noteId; this.title = isProtected ? "[protected]" : title; - this.type = type; + this.type = type as NoteType; this.mime = mime; this.blobId = blobId; this.utcDateModified = utcDateModified; // used for caching of images @@ -528,33 +528,22 @@ class SNote extends AbstractShacaEntity { } getIcon(filterByPrefix: string[] = []) { - return `tn-icon ${this.#getIconInternal(filterByPrefix)}`; - } - - #getIconInternal(filterByPrefix: string[] = []) { const iconClassLabels = this.getLabels("iconClass").filter(label => { if (filterByPrefix.length === 0) { return true; } return filterByPrefix.some(prefix => label.value.startsWith(prefix)); }); + const icon = getNoteIcon({ + noteId: this.noteId, + type: this.type, + mime: this.mime, + workspaceIconClass: undefined, + iconClass: iconClassLabels.length > 0 ? iconClassLabels[0].value : undefined, + isFolder: this.isFolder.bind(this) + }); - if (iconClassLabels && iconClassLabels.length > 0) { - return iconClassLabels[0].value; - } else if (this.noteId === "root") { - return "bx bx-home-alt-2"; - } - if (this.noteId === "_share") { - return "bx bx-share-alt"; - } else if (this.type === "text") { - if (this.isFolder()) { - return "bx bx-folder"; - } - return "bx bx-note"; - } else if (this.type === "code" && this.mime.startsWith("text/x-sql")) { - return "bx bx-data"; - } - return NOTE_TYPE_ICONS[this.type]; + return `tn-icon ${icon}`; } isFolder() {