Notes/src/public/app/widgets/containers/launcher_container.js

71 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-08-04 23:00:32 +02:00
import FlexContainer from "./flex_container.js";
import froca from "../../services/froca.js";
2022-12-01 13:07:23 +01:00
import appContext from "../../components/app_context.js";
2022-12-01 16:22:04 +01:00
import LauncherWidget from "./launcher.js";
2022-08-04 23:00:32 +02:00
2022-12-01 10:16:57 +01:00
export default class LauncherContainer extends FlexContainer {
2022-08-04 23:00:32 +02:00
constructor() {
super('column');
2022-12-01 10:16:57 +01:00
this.id('launcher-container');
2022-08-04 23:00:32 +02:00
this.css('height', '100%');
this.filling();
this.load();
}
async load() {
this.children = [];
2022-12-01 10:16:57 +01:00
const visibleLaunchersRoot = await froca.getNote('lb_visiblelaunchers', true);
2022-08-06 15:00:56 +02:00
2022-12-01 10:16:57 +01:00
if (!visibleLaunchersRoot) {
console.log("Visible launchers root note doesn't exist.");
2022-08-06 15:00:56 +02:00
return;
}
2022-08-04 23:00:32 +02:00
2022-11-28 23:39:23 +01:00
await Promise.allSettled(
2022-12-01 10:16:57 +01:00
(await visibleLaunchersRoot.getChildNotes())
2022-12-01 16:22:04 +01:00
.map(async launcherNote => {
try {
const launcherWidget = new LauncherWidget(launcherNote);
await launcherWidget.initLauncher();
this.child(launcherWidget);
}
catch (e) {
console.error(e.message);
}
})
2022-11-28 23:39:23 +01:00
);
2022-08-04 23:00:32 +02:00
this.$widget.empty();
this.renderChildren();
2022-11-27 23:43:25 +01:00
await this.handleEventInChildren('initialRenderComplete');
const activeContext = appContext.tabManager.getActiveContext();
2022-11-28 23:39:23 +01:00
if (activeContext) {
await this.handleEvent('setNoteContext', {
noteContext: activeContext
});
if (activeContext.notePath) {
await this.handleEvent('noteSwitched', {
noteContext: activeContext,
notePath: activeContext.notePath
});
}
}
2022-11-27 23:43:25 +01:00
}
2022-08-04 23:00:32 +02:00
entitiesReloadedEvent({loadResults}) {
2022-08-07 15:34:59 +02:00
if (loadResults.getNoteIds().find(noteId => froca.notes[noteId]?.isLaunchBarConfig())
|| loadResults.getBranches().find(branch => branch.parentNoteId.startsWith("lb_"))
|| loadResults.getAttributes().find(attr => froca.notes[attr.noteId]?.isLaunchBarConfig())) {
2022-08-04 23:00:32 +02:00
this.load();
}
}
}