Skip to content

Build your personal knowledge base with Trilium Notes

feat(mobile): open the right pane's tabs from the title row

Elian Doran12f674c83310
diff --git a/apps/client/src/layouts/mobile_layout.tsx b/apps/client/src/layouts/mobile_layout.tsx
index 31859b6d35..bdd8d0cae4 100644
--- a/apps/client/src/layouts/mobile_layout.tsx
+++ b/apps/client/src/layouts/mobile_layout.tsx
@@ -16,6 +16,7 @@ import NoteTitleActions from "../widgets/layout/NoteTitleActions.jsx";
import HideKeyboardButton from "../widgets/mobile_widgets/hide_keyboard_button.jsx";
import MobileDetailMenu from "../widgets/mobile_widgets/mobile_detail_menu.js";
import MobileNoteNavigator from "../widgets/mobile_widgets/MobileNoteNavigator.jsx";
+import MobileNotePanel from "../widgets/mobile_widgets/MobileNotePanel.jsx";
import ScreenContainer from "../widgets/mobile_widgets/screen_container.js";
import SidebarContainer from "../widgets/mobile_widgets/sidebar_container.js";
import ToggleSidebarButton from "../widgets/mobile_widgets/toggle_sidebar_button.jsx";
@@ -69,6 +70,7 @@ export default class MobileLayout {
.child(<NoteIconWidget />)
.child(<NoteTitleWidget />)
.child(<NoteBadges />)
+ .child(<MobileNotePanel />)
.child(<MobileDetailMenu />)
)
.child(
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 46ee4ebe3e..be1fd20124 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1324,7 +1324,8 @@
"backlinks": "Backlinks",
"content_language_switcher": "Content language: {{language}}",
"insert_child_note_short": "Child note",
- "create_new_split_short": "New split"
+ "create_new_split_short": "New split",
+ "note_panel": "Note panel"
},
"note_icon": {
"change_note_icon": "Change note icon",
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNotePanel.css b/apps/client/src/widgets/mobile_widgets/MobileNotePanel.css
new file mode 100644
index 0000000000..d4b039b4b0
--- /dev/null
+++ b/apps/client/src/widgets/mobile_widgets/MobileNotePanel.css
@@ -0,0 +1,32 @@
+.component.mobile-note-panel-button {
+ contain: none;
+}
+
+body.mobile .modal.mobile-note-panel {
+ .modal-dialog {
+ height: 85vh;
+ }
+
+ .modal-content {
+ flex: 1;
+ min-height: 0;
+ padding-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom));
+ }
+
+ .modal-header .tab-strip {
+ flex: 1;
+ }
+
+ .modal-body {
+ flex: 1 1 auto;
+ min-height: 0;
+ display: flex;
+ padding: 0;
+ }
+
+ #right-pane {
+ flex: 1;
+ min-height: 0;
+ background: transparent;
+ }
+}
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNotePanel.tsx b/apps/client/src/widgets/mobile_widgets/MobileNotePanel.tsx
new file mode 100644
index 0000000000..66d89254f4
--- /dev/null
+++ b/apps/client/src/widgets/mobile_widgets/MobileNotePanel.tsx
@@ -0,0 +1,58 @@
+import "./MobileNotePanel.css";
+
+import { createPortal } from "preact";
+import { useState } from "preact/hooks";
+
+import { WidgetsByParent } from "../../services/bundle";
+import { t } from "../../services/i18n";
+import ActionButton from "../react/ActionButton";
+import { useNoteContext } from "../react/hooks";
+import Modal from "../react/Modal";
+import { RightPaneTabBodies, useRightPaneTabs } from "../sidebar/RightPanelContainer";
+import RightPaneTabs, { 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() {
+ const [ shown, setShown ] = useState(false);
+ const { note } = useNoteContext();
+
+ return (
+ <div className="mobile-note-panel-button">
+ {note && <ActionButton
+ icon="bx bx-sidebar"
+ text={t("mobile_detail_menu.note_panel")}
+ onClick={() => setShown(true)}
+ />}
+ {createPortal(<MobileNotePanelModal shown={shown} onHidden={() => setShown(false)} />, document.body)}
+ </div>
+ );
+}
+
+function MobileNotePanelModal({ shown, onHidden }: { shown: boolean; onHidden: () => void }) {
+ const tabs = useRightPaneTabs(shown, NO_CUSTOM_WIDGETS).filter((tab) => tab.id !== "attributes");
+ const [ selectedTabId, setSelectedTabId ] = useState<RightPaneTabId>();
+ const activeTab = tabs.find((tab) => tab.id === selectedTabId) ?? tabs[0];
+
+ return (
+ <Modal
+ className="mobile-note-panel"
+ size="md"
+ title={<RightPaneTabs tabs={tabs} activeTabId={activeTab?.id} onSelect={setSelectedTabId} />}
+ ariaLabel={t("mobile_detail_menu.note_panel")}
+ show={shown}
+ onHidden={onHidden}
+ >
+ {/* The widgets' card, TOC and highlight styles are scoped to `#right-pane`, which the
+ mobile layout has no other element for. */}
+ <div id="right-pane">
+ <RightPaneTabBodies tabs={tabs} activeTabId={activeTab?.id} />
+ </div>
+ </Modal>
+ );
+}
diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
index 013f7bb131..6ebdbbc15b 100644
--- a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
@@ -51,7 +51,7 @@ export interface RightPaneTabContents extends RightPaneTabDefinition {
export default function RightPanelContainer({ widgetsByParent }: { widgetsByParent: WidgetsByParent }) {
const { mode, visible, mounted, togglePeek, toggleDocked, dock, close, dismiss } = usePaneMode("rightPaneVisible", "right");
- const tabs = useItems(mounted, widgetsByParent);
+ const tabs = useRightPaneTabs(mounted, widgetsByParent);
// This window's own choice, seeded from the option and written back for the next window to start
// from — the same treatment usePaneMode gives the pane's visibility. Subscribing to the option
// (useTriliumOption) would let a click in one window flip the strip in every other.
@@ -68,14 +68,6 @@ export default function RightPanelContainer({ widgetsByParent }: { widgetsByPare
// overwriting the choice, so it is back as soon as the note has that tab again.
const activeTab = tabs.find((tab) => tab.id === selectedTabId) ?? tabs[0];
- // A tab's widgets are mounted when it is first opened and kept mounted afterwards: switching back
- // is instant and stateful (a chat in progress survives it), while a tab never opened costs
- // nothing — which is what keeps the LLM chat's bundle out of the pane until it is asked for.
- const openedTabs = useRef(new Set<RightPaneTabId>());
- if (activeTab) {
- openedTabs.current.add(activeTab.id);
- }
-
// Legacy entry points (tab-row toggle, empty-state button) open/close the *docked* pane;
// the keyboard shortcut peeks it (same as clicking the peek button).
useTriliumEvent("toggleRightPane", toggleDocked);
@@ -172,25 +164,7 @@ export default function RightPanelContainer({ widgetsByParent }: { widgetsByPare
</div>
</div>
{tabs.length > 0 ? (
- tabs.filter((tab) => openedTabs.current.has(tab.id)).map((tab) => (
- <div
- key={tab.id}
- role="tabpanel"
- class={clsx("right-pane-tab-body", tab.id !== activeTab?.id && "hidden-ext")}
- >
- {/* Collapsing the only widget of a tab would leave the tab empty,
- so a tab of one offers no collapsing at all. */}
- <CollapsibleWidgets.Provider value={tab.items.length > 1}>
- <ExpandWidgetRequests.Provider value={expandRequest}>
- {tab.items.length > 0 ? tab.items : (
- // A tab that stays for a note it has nothing to show
- // (see RightPaneTabDefinition.alwaysShown) says so.
- <NoItems icon={tab.icon} text={t("right_pane.empty_message")} />
- )}
- </ExpandWidgetRequests.Provider>
- </CollapsibleWidgets.Provider>
- </div>
- ))
+ <RightPaneTabBodies tabs={tabs} activeTabId={activeTab?.id} expandRequest={expandRequest} />
) : (
<NoItems
icon="bx bx-sidebar"
@@ -213,7 +187,44 @@ export default function RightPanelContainer({ widgetsByParent }: { widgetsByPare
);
}
-function useItems(rightPaneVisible: boolean, widgetsByParent: WidgetsByParent): RightPaneTabContents[] {
+/**
+ * The bodies of the pane's tabs, all but the active one hidden. A tab's widgets are mounted when it is
+ * first opened and kept mounted afterwards: switching back is instant and keeps its state (a chat in
+ * progress), and a tab never opened costs nothing, which keeps the LLM chat's bundle out until it is
+ * asked for.
+ */
+export function RightPaneTabBodies({ tabs, activeTabId, expandRequest }: { tabs: RightPaneTabContents[]; activeTabId?: RightPaneTabId; expandRequest?: ExpandWidgetRequest | null }) {
+ const openedTabs = useRef(new Set<RightPaneTabId>());
+ if (activeTabId) {
+ openedTabs.current.add(activeTabId);
+ }
+
+ return tabs.filter((tab) => openedTabs.current.has(tab.id)).map((tab) => (
+ <div
+ key={tab.id}
+ role="tabpanel"
+ class={clsx("right-pane-tab-body", tab.id !== activeTabId && "hidden-ext")}
+ >
+ {/* Collapsing the only widget of a tab would leave the tab empty, so a tab of one offers
+ no collapsing at all. */}
+ <CollapsibleWidgets.Provider value={tab.items.length > 1}>
+ <ExpandWidgetRequests.Provider value={expandRequest ?? null}>
+ {tab.items.length > 0 ? tab.items : (
+ // A tab that stays for a note it has nothing to show
+ // (see RightPaneTabDefinition.alwaysShown) says so.
+ <NoItems icon={tab.icon} text={t("right_pane.empty_message")} />
+ )}
+ </ExpandWidgetRequests.Provider>
+ </CollapsibleWidgets.Provider>
+ </div>
+ ));
+}
+
+/**
+ * The pane's tabs with the widgets enabled for the active note, or none while `rightPaneVisible` is
+ * false. Shared by the desktop pane and the mobile note panel.
+ */
+export function useRightPaneTabs(rightPaneVisible: boolean, widgetsByParent: WidgetsByParent): RightPaneTabContents[] {
const { note } = useActiveNoteContext();
const noteType = useNoteProperty(note, "type");
const noteMime = useNoteProperty(note, "mime");