Skip to content

Build your personal knowledge base with Trilium Notes

feat(mobile): show the right pane's script widgets in the note panel

Elian Doran9b30f1d038c6
diff --git a/apps/client/src/layouts/mobile_layout.tsx b/apps/client/src/layouts/mobile_layout.tsx
index bdd8d0cae4..fafef5c739 100644
--- a/apps/client/src/layouts/mobile_layout.tsx
+++ b/apps/client/src/layouts/mobile_layout.tsx
@@ -1,6 +1,7 @@
import "./mobile_layout.css";
import type AppContext from "../components/app_context.js";
+import type { WidgetsByParent } from "../services/bundle.js";
import GlobalMenuWidget from "../widgets/buttons/global_menu.js";
import CloseZenModeButton from "../widgets/close_zen_button.js";
import NoteList from "../widgets/collections/NoteList.jsx";
@@ -31,6 +32,12 @@ import MobileEditorToolbar from "../widgets/type_widgets/text/mobile_editor_tool
import { applyModals } from "./layout_commons.js";
export default class MobileLayout {
+ private customWidgets: WidgetsByParent;
+
+ constructor(customWidgets: WidgetsByParent) {
+ this.customWidgets = customWidgets;
+ }
+
getRootWidget(appContext: typeof AppContext) {
const rootContainer = new RootContainer(true)
.setParent(appContext)
@@ -70,7 +77,7 @@ export default class MobileLayout {
.child(<NoteIconWidget />)
.child(<NoteTitleWidget />)
.child(<NoteBadges />)
- .child(<MobileNotePanel />)
+ .child(<MobileNotePanel widgetsByParent={this.customWidgets} />)
.child(<MobileDetailMenu />)
)
.child(
diff --git a/apps/client/src/mobile.ts b/apps/client/src/mobile.ts
index 2ef5bfd9e6..a066dec9a7 100644
--- a/apps/client/src/mobile.ts
+++ b/apps/client/src/mobile.ts
@@ -1,4 +1,5 @@
import appContext from "./components/app_context.js";
+import bundleService from "./services/bundle.js";
import { setupClipboardImageEmbed } from "./services/clipboard_image_embed.js";
import glob from "./services/glob.js";
import { preloadCommonNoteTypes } from "./widgets/note_types.js";
@@ -9,10 +10,12 @@ await appContext.earlyInit();
setupClipboardImageEmbed();
+const widgetBundles = await bundleService.getWidgetBundlesByParent();
+
// A dynamic import is required for layouts since they initialize components which require translations.
const MobileLayout = (await import("./layouts/mobile_layout.js")).default;
-appContext.setLayout(new MobileLayout());
+appContext.setLayout(new MobileLayout(widgetBundles));
/** Resolves once the layout is rendered and froca has the note tree; see desktop.ts. */
export const ready = appContext.start().then(preloadCommonNoteTypes);
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNotePanel.tsx b/apps/client/src/widgets/mobile_widgets/MobileNotePanel.tsx
index 8326feb319..56eb763870 100644
--- a/apps/client/src/widgets/mobile_widgets/MobileNotePanel.tsx
+++ b/apps/client/src/widgets/mobile_widgets/MobileNotePanel.tsx
@@ -3,7 +3,7 @@ import "./MobileNotePanel.css";
import { createPortal } from "preact";
import { useState } from "preact/hooks";
-import { WidgetsByParent } from "../../services/bundle";
+import type { WidgetsByParent } from "../../services/bundle";
import { t } from "../../services/i18n";
import ActionButton from "../react/ActionButton";
import { useNoteContext } from "../react/hooks";
@@ -13,14 +13,11 @@ import { RightPaneTabBodies, useRightPaneTabs } from "../sidebar/RightPanelConta
import { NavigatedInNote } from "../sidebar/RightPanelWidget";
import { RightPaneTabId } from "../sidebar/RightPaneTabs";
-/** The mobile layout loads no script widgets for the right pane. */
-const NO_CUSTOM_WIDGETS = new WidgetsByParent();
-
/**
* The title-row button that opens the desktop right pane's tabs in a modal, for the mobile layout.
* The attributes tab is left out, since the note menu already opens `NoteAttributesDialog`.
*/
-export default function MobileNotePanel() {
+export default function MobileNotePanel({ widgetsByParent }: { widgetsByParent: WidgetsByParent }) {
const [ shown, setShown ] = useState(false);
const { note } = useNoteContext();
@@ -31,13 +28,13 @@ export default function MobileNotePanel() {
text={t("mobile_detail_menu.note_panel")}
onClick={() => setShown(true)}
/>}
- {createPortal(<MobileNotePanelModal shown={shown} onHidden={() => setShown(false)} />, document.body)}
+ {createPortal(<MobileNotePanelModal shown={shown} onHidden={() => setShown(false)} widgetsByParent={widgetsByParent} />, document.body)}
</div>
);
}
-function MobileNotePanelModal({ shown, onHidden }: { shown: boolean; onHidden: () => void }) {
- const tabs = useRightPaneTabs(shown, NO_CUSTOM_WIDGETS).filter((tab) => tab.id !== "attributes");
+function MobileNotePanelModal({ shown, onHidden, widgetsByParent }: { shown: boolean; onHidden: () => void; widgetsByParent: WidgetsByParent }) {
+ const tabs = useRightPaneTabs(shown, widgetsByParent).filter((tab) => tab.id !== "attributes");
const [ selectedTabId, setSelectedTabId ] = useState<RightPaneTabId>();
const activeTab = tabs.find((tab) => tab.id === selectedTabId) ?? tabs[0];