From 8300acd30b32c28479203e1a82ac0b6d67f1bd42 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 22 Nov 2024 20:36:08 +0200 Subject: [PATCH] refactor(client): add support for optional children in layout --- src/public/app/layouts/desktop_layout.js | 16 +++++++++------- src/public/app/widgets/basic_widget.js | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/public/app/layouts/desktop_layout.js b/src/public/app/layouts/desktop_layout.js index 34fe4454b..4f0a2d2f5 100644 --- a/src/public/app/layouts/desktop_layout.js +++ b/src/public/app/layouts/desktop_layout.js @@ -92,15 +92,17 @@ export default class DesktopLayout { getRootWidget(appContext) { appContext.noteTreeWidget = new NoteTreeWidget(); + const launcherPaneIsHorizontal = true; + const launcherPane = new FlexContainer("column") + .id("launcher-pane") + .css("width", "53px") + .child(new GlobalMenuWidget()) + .child(new LauncherContainer()) + .child(new LeftPaneToggleWidget()); + return new RootContainer() .setParent(appContext) - .child(new FlexContainer("column") - .id("launcher-pane") - .css("width", "53px") - .child(new GlobalMenuWidget()) - .child(new LauncherContainer()) - .child(new LeftPaneToggleWidget()) - ) + .optChild(!launcherPaneIsHorizontal, launcherPane) .child(new LeftPaneContainer() .child(new QuickSearchWidget()) .child(appContext.noteTreeWidget) diff --git a/src/public/app/widgets/basic_widget.js b/src/public/app/widgets/basic_widget.js index 4dd580bd2..bf38552c8 100644 --- a/src/public/app/widgets/basic_widget.js +++ b/src/public/app/widgets/basic_widget.js @@ -40,6 +40,21 @@ class BasicWidget extends Component { return this; } + /** + * Conditionally adds the given components as children to this component. + * + * @param {boolean} condition whether to add the components. + * @param {...any} components the components to be added as children to this component provided the condition is truthy. + * @returns self for chaining. + */ + optChild(condition, ...components) { + if (condition) { + return this.child(...components); + } else { + return this; + } + } + id(id) { this.attrs.id = id; return this;