Skip to content

Build your personal knowledge base with Trilium Notes

feat(mobile): stack the note panel's sections in one scroll

Elian Dorandcf47057cf67
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNotePanel.css b/apps/client/src/widgets/mobile_widgets/MobileNotePanel.css
index aa0d32acea..cd758f88aa 100644
--- a/apps/client/src/widgets/mobile_widgets/MobileNotePanel.css
+++ b/apps/client/src/widgets/mobile_widgets/MobileNotePanel.css
@@ -25,4 +25,30 @@ body.mobile .modal.mobile-note-panel {
min-height: 0;
background: transparent;
}
+
+ #right-pane .right-pane-flat-tab-body {
+ flex: 1;
+ min-height: 0;
+ display: flex;
+ flex-direction: column;
+ overflow-y: auto;
+
+ > .card:only-child > .card-header:has(> .card-header-buttons:empty) {
+ display: none;
+ }
+
+ > .card {
+ border-bottom: 1px solid var(--main-border-color);
+ }
+
+ > :is(#pdf-pages, #noteMap) {
+ order: 1;
+ }
+
+ > :is(#pdf-pages, #noteMap):not(.grow) .card-body {
+ display: flex;
+ flex-direction: column;
+ height: 60vh;
+ }
+ }
}
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNotePanel.tsx b/apps/client/src/widgets/mobile_widgets/MobileNotePanel.tsx
index 56eb763870..4b890f4f1c 100644
--- a/apps/client/src/widgets/mobile_widgets/MobileNotePanel.tsx
+++ b/apps/client/src/widgets/mobile_widgets/MobileNotePanel.tsx
@@ -51,7 +51,7 @@ function MobileNotePanelModal({ shown, onHidden, widgetsByParent }: { shown: boo
mobile layout has no other element for. */}
<div id="right-pane">
<NavigatedInNote.Provider value={onHidden}>
- <RightPaneTabBodies tabs={tabs} activeTabId={activeTab?.id} />
+ <RightPaneTabBodies tabs={tabs} activeTabId={activeTab?.id} flat />
</NavigatedInNote.Provider>
</div>
</Modal>
diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
index 6ebdbbc15b..0699456d57 100644
--- a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
@@ -29,7 +29,7 @@ import PdfAnnotations from "./pdf/PdfAnnotations";
import PdfAttachments from "./pdf/PdfAttachments";
import PdfLayers from "./pdf/PdfLayers";
import PdfPages from "./pdf/PdfPages";
-import RightPanelWidget, { CollapsibleWidgets, ExpandWidgetRequest, ExpandWidgetRequests } from "./RightPanelWidget";
+import RightPanelWidget, { CollapsibleWidgets, ExpandWidgetRequest, ExpandWidgetRequests, StackedWidgets } from "./RightPanelWidget";
import RightPaneTabs, { RIGHT_PANE_TABS, RightPaneTabDefinition, RightPaneTabId } from "./RightPaneTabs";
import TableOfContents from "./TableOfContents";
@@ -192,8 +192,11 @@ export default function RightPanelContainer({ widgetsByParent }: { widgetsByPare
* 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.
+ *
+ * A `flat` tab scrolls as a whole, its widgets stacked at their content's height with nothing to
+ * collapse, as the mobile note panel lays it out.
*/
-export function RightPaneTabBodies({ tabs, activeTabId, expandRequest }: { tabs: RightPaneTabContents[]; activeTabId?: RightPaneTabId; expandRequest?: ExpandWidgetRequest | null }) {
+export function RightPaneTabBodies({ tabs, activeTabId, expandRequest, flat }: { tabs: RightPaneTabContents[]; activeTabId?: RightPaneTabId; expandRequest?: ExpandWidgetRequest | null; flat?: boolean }) {
const openedTabs = useRef(new Set<RightPaneTabId>());
if (activeTabId) {
openedTabs.current.add(activeTabId);
@@ -203,18 +206,20 @@ export function RightPaneTabBodies({ tabs, activeTabId, expandRequest }: { tabs:
<div
key={tab.id}
role="tabpanel"
- class={clsx("right-pane-tab-body", tab.id !== activeTabId && "hidden-ext")}
+ class={clsx(flat ? "right-pane-flat-tab-body" : "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 value={!flat && tab.items.length > 1}>
+ <StackedWidgets.Provider value={!!flat && 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>
+ </StackedWidgets.Provider>
</CollapsibleWidgets.Provider>
</div>
));
diff --git a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx b/apps/client/src/widgets/sidebar/RightPanelWidget.tsx
index 298585ee6f..49eb92cec4 100644
--- a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx
+++ b/apps/client/src/widgets/sidebar/RightPanelWidget.tsx
@@ -26,6 +26,12 @@ export interface ExpandWidgetRequest {
/** The pending {@link ExpandWidgetRequest}, set by whoever lays the widgets out. */
export const ExpandWidgetRequests = createContext<ExpandWidgetRequest | null>(null);
+/**
+ * Lay the widgets out one under the next at the height of their content, ignoring `grow`. Set by a
+ * host whose whole tab scrolls, such as the mobile note panel, for a tab of more than one widget.
+ */
+export const StackedWidgets = createContext(false);
+
/**
* Called after a widget scrolls the note to a place in it (a heading, a PDF page), set by a host that
* covers the note, such as the mobile note panel, so that it can close and show that place.
@@ -69,6 +75,7 @@ export default function RightPanelWidget({ id, title, buttons, children, contain
const parentComponent = useContext(ParentComponent);
const collapsible = useContext(CollapsibleWidgets);
const expandRequest = useContext(ExpandWidgetRequests);
+ const stacked = useContext(StackedWidgets);
// Whatever an earlier layout collapsed stays remembered but is disregarded here: the widget is all
// its tab has, so a collapsed one would leave nothing behind, chevron included, to expand it again.
const expanded = collapsible ? !collapsedByUser : true;
@@ -108,7 +115,7 @@ export default function RightPanelWidget({ id, title, buttons, children, contain
className={clsx("card widget", {
collapsed: !expanded,
"not-collapsible": !collapsible,
- grow,
+ grow: grow && !stacked,
highlighted
})}
// The flash lasts as long as its animation (see RightPanelContainer.css) rather than a