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

77 lines
2.3 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 {
constructor(isHorizontalLayout) {
super(isHorizontalLayout ? "row" : "column");
2022-08-04 23:00:32 +02:00
2022-12-01 10:16:57 +01:00
this.id('launcher-container');
this.css(isHorizontalLayout ? "width" : 'height', '100%');
2022-08-04 23:00:32 +02:00
this.filling();
this.isHorizontalLayout = isHorizontalLayout;
2022-08-04 23:00:32 +02:00
this.load();
}
async load() {
2022-12-11 22:26:18 +01:00
await froca.initializedPromise;
2022-12-21 16:11:00 +01:00
const visibleLaunchersRoot = await froca.getNote('_lbVisibleLaunchers', 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
const newChildren = [];
for (const launcherNote of await visibleLaunchersRoot.getChildNotes()) {
try {
const launcherWidget = new LauncherWidget(this.isHorizontalLayout);
const success = await launcherWidget.initLauncher(launcherNote);
if (success) {
newChildren.push(launcherWidget);
}
}
catch (e) {
console.error(e);
}
}
2022-08-04 23:00:32 +02:00
this.children = [];
this.child(...newChildren);
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}) {
if (loadResults.getBranchRows().find(branch => froca.getNoteFromCache(branch.parentNoteId)?.isLaunchBarConfig())) {
2023-06-30 11:18:34 +02:00
// changes in note placement require reload of all launchers, all other changes are handled by individual
2022-12-03 21:11:49 +01:00
// launchers
2022-08-04 23:00:32 +02:00
this.load();
}
}
}