feat(autocomplete): support default icons like on client

This commit is contained in:
Elian Doran 2025-03-29 22:18:42 +02:00
parent a9193fdcd4
commit 766b0723f7
No known key found for this signature in database
2 changed files with 68 additions and 1 deletions

View File

@ -57,7 +57,7 @@ function getNoteTitleAndIcon(childNoteId: string, parentNoteId?: string) {
}
const title = childNote.getTitleOrProtected();
const icon = childNote.getLabelValue("iconClass");
const icon = childNote.getIcon();
const branch = parentNote ? becca.getBranchFromChildAndParent(childNote.noteId, parentNote.noteId) : null;

View File

@ -27,6 +27,26 @@ dayjs.extend(utc);
const LABEL = "label";
const RELATION = "relation";
// TODO: Deduplicate with fnote
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;
@ -1691,6 +1711,53 @@ class BNote extends AbstractBeccaEntity<BNote> {
return pojo;
}
// TODO: Deduplicate with fnote
getIcon() {
const iconClassLabels = this.getLabels("iconClass");
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";
} else {
return "bx bx-note";
}
} else if (this.type === "code" && this.mime.startsWith("text/x-sql")) {
return "bx bx-data";
} else {
return NOTE_TYPE_ICONS[this.type];
}
}
// TODO: Deduplicate with fnote
isFolder() {
return this.type === "search" || this.getFilteredChildBranches().length > 0;
}
// TODO: Deduplicate with fnote
getFilteredChildBranches() {
let childBranches = this.getChildBranches();
if (!childBranches) {
console.error(`No children for '${this.noteId}'. This shouldn't happen.`);
return [];
}
// we're not checking hideArchivedNotes since that would mean we need to lazy load the child notes
// which would seriously slow down everything.
// we check this flag only once user chooses to expand the parent. This has the negative consequence that
// note may appear as a folder but not contain any children when all of them are archived
return childBranches;
}
}
export default BNote;