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

57 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-10-05 22:08:02 +02:00
import FlexContainer from "./containers/flex_container.js";
import OpenNoteButtonWidget from "./buttons/open_note_button_widget.js";
2021-10-07 21:57:20 +02:00
import BookmarkFolderWidget from "./buttons/bookmark_folder.js";
2022-12-04 13:16:05 +01:00
import froca from "../services/froca.js";
2025-02-01 11:04:49 +02:00
import utils from "../services/utils.js";
2021-10-05 22:08:02 +02:00
export default class BookmarkButtons extends FlexContainer {
constructor(isHorizontalLayout) {
super(isHorizontalLayout ? "row" : "column");
2021-10-05 22:08:02 +02:00
this.contentSized();
this.settings = {};
2021-10-05 22:08:02 +02:00
}
async refresh() {
this.$widget.empty();
this.children = [];
this.noteIds = [];
2025-01-09 18:07:02 +02:00
const bookmarkParentNote = await froca.getNote("_lbBookmarks");
2022-12-04 13:16:05 +01:00
for (const note of await bookmarkParentNote.getChildNotes()) {
2021-10-05 22:08:02 +02:00
this.noteIds.push(note.noteId);
2025-01-09 18:07:02 +02:00
const buttonWidget = note.isLabelTruthy("bookmarkFolder") ? new BookmarkFolderWidget(note) : new OpenNoteButtonWidget(note).class("launcher-button");
if (this.settings.titlePlacement) {
if (!buttonWidget.settings) {
buttonWidget = {};
}
buttonWidget.settings.titlePlacement = this.settings.titlePlacement;
}
2022-12-11 13:20:37 +01:00
2021-10-05 22:08:02 +02:00
this.child(buttonWidget);
this.$widget.append(buttonWidget.render());
buttonWidget.refreshIcon();
}
2025-02-01 11:04:49 +02:00
utils.reloadTray();
2021-10-05 22:08:02 +02:00
}
initialRenderCompleteEvent() {
this.refresh();
}
2025-01-09 18:07:02 +02:00
entitiesReloadedEvent({ loadResults }) {
if (loadResults.getBranchRows().find((branch) => branch.parentNoteId === "_lbBookmarks")) {
2021-10-05 22:08:02 +02:00
this.refresh();
}
2025-01-09 18:07:02 +02:00
if (loadResults.getAttributeRows().find((attr) => attr.type === "label" && ["iconClass", "workspaceIconClass", "bookmarkFolder"].includes(attr.name) && this.noteIds.includes(attr.noteId))) {
2021-10-05 22:08:02 +02:00
this.refresh();
}
}
}