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";
|
2021-10-05 22:08:02 +02:00
|
|
|
|
|
|
|
export default class BookmarkButtons extends FlexContainer {
|
2024-11-24 12:17:47 +02:00
|
|
|
constructor(isHorizontalLayout) {
|
|
|
|
super(isHorizontalLayout ? "row" : "column");
|
2021-10-05 22:08:02 +02:00
|
|
|
|
|
|
|
this.contentSized();
|
|
|
|
}
|
|
|
|
|
|
|
|
async refresh() {
|
|
|
|
this.$widget.empty();
|
|
|
|
this.children = [];
|
|
|
|
this.noteIds = [];
|
|
|
|
|
2022-12-21 16:11:00 +01: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);
|
|
|
|
|
2023-06-29 00:14:12 +02:00
|
|
|
const buttonWidget = note.isLabelTruthy("bookmarkFolder")
|
2021-10-07 21:57:20 +02:00
|
|
|
? new BookmarkFolderWidget(note)
|
2022-12-19 23:19:47 +01:00
|
|
|
: new OpenNoteButtonWidget(note)
|
|
|
|
.class("launcher-button");
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
initialRenderCompleteEvent() {
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
entitiesReloadedEvent({loadResults}) {
|
2023-06-05 16:12:02 +02:00
|
|
|
if (loadResults.getBranchRows().find(branch => branch.parentNoteId === '_lbBookmarks')) {
|
2021-10-05 22:08:02 +02:00
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
2023-06-05 16:12:02 +02:00
|
|
|
if (loadResults.getAttributeRows().find(attr => attr.type === 'label'
|
2022-12-24 13:31:38 +01:00
|
|
|
&& ['iconClass', 'workspaceIconClass', 'bookmarkFolder'].includes(attr.name)
|
2021-10-05 22:08:02 +02:00
|
|
|
&& this.noteIds.includes(attr.noteId))
|
|
|
|
) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|