trilium/src/public/app/widgets/bookmark_buttons.js

53 lines
1.5 KiB
JavaScript

import FlexContainer from "./containers/flex_container.js";
import OpenNoteButtonWidget from "./buttons/open_note_button_widget.js";
import BookmarkFolderWidget from "./buttons/bookmark_folder.js";
import froca from "../services/froca.js";
export default class BookmarkButtons extends FlexContainer {
constructor() {
super("column");
this.contentSized();
}
async refresh() {
this.$widget.empty();
this.children = [];
this.noteIds = [];
const bookmarkParentNote = await froca.getNote('lbBookmarks');
for (const note of await bookmarkParentNote.getChildNotes()) {
this.noteIds.push(note.noteId);
const buttonWidget = note.hasLabel("bookmarkFolder")
? new BookmarkFolderWidget(note)
: new OpenNoteButtonWidget(note)
.class("launcher-button");
this.child(buttonWidget);
this.$widget.append(buttonWidget.render());
buttonWidget.refreshIcon();
}
}
initialRenderCompleteEvent() {
this.refresh();
}
entitiesReloadedEvent({loadResults}) {
if (loadResults.getBranches().find(branch => branch.parentNoteId === 'lbBookmarks')) {
this.refresh();
}
if (loadResults.getAttributes().find(attr => attr.type === 'label'
&& ['iconClass', 'workspaceIconClass'].includes(attr.name)
&& this.noteIds.includes(attr.noteId))
) {
this.refresh();
}
}
}