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

53 lines
1.6 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";
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();
}
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);
const buttonWidget = note.isLabelTruthy("bookmarkFolder")
2021-10-07 21:57:20 +02:00
? new BookmarkFolderWidget(note)
: 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}) {
if (loadResults.getBranchRows().find(branch => branch.parentNoteId === '_lbBookmarks')) {
2021-10-05 22:08:02 +02:00
this.refresh();
}
if (loadResults.getAttributeRows().find(attr => attr.type === 'label'
&& ['iconClass', 'workspaceIconClass', 'bookmarkFolder'].includes(attr.name)
2021-10-05 22:08:02 +02:00
&& this.noteIds.includes(attr.noteId))
) {
this.refresh();
}
}
}