Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(options): basic master-detail for mobile
Elian Doran68cadadc0bfd
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 6909a8883a..f55bc1ee08 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -737,7 +737,8 @@"show_highlights_list": "Show Highlights List"},"options": {- "title": "Options"+ "title": "Options",+ "back": "Back to all options"},"global_menu": {"menu": "Menu",diff --git a/apps/client/src/widgets/dialogs/OptionsDialog.css b/apps/client/src/widgets/dialogs/OptionsDialog.cssindex 41d3882543..5e88dc2750 100644--- a/apps/client/src/widgets/dialogs/OptionsDialog.css+++ b/apps/client/src/widgets/dialogs/OptionsDialog.css@@ -32,7 +32,7 @@ body.mobile .modal.options-dialog .modal-dialog {/* The main header only carries the window (maximize/close) buttons, with the title moved into thesidebar. Float it over the content so it doesn't leave a tall empty band at the top. */-.modal.options-dialog .modal-main > .modal-header {+body.desktop .modal.options-dialog .modal-main > .modal-header {position: absolute;top: 0;right: 4px;@@ -45,7 +45,58 @@ body.mobile .modal.options-dialog .modal-dialog {/* Push the page content below the floating header. The variable is also read by the theme(theme-next/pages.css) and zeroed on pages that manage their own spacing (e.g. shortcuts). */-.modal.options-dialog .note-detail-content-widget-content.options {+body.desktop .modal.options-dialog .note-detail-content-widget-content.options {--options-first-item-top-margin: 60px;padding-top: var(--options-first-item-top-margin);}++/* On mobile the sidebar and the page become a master-detail flow instead: the dialog first shows+ only the full-height list of pages (replacing the generic bottom-strip sidebar layout from+ style.css), and tapping an entry reveals the page with a back button in the header. */+body.mobile .modal.options-dialog .modal-content {+ height: 100%;+}++body.mobile .modal.options-dialog .modal-body {+ height: auto;+ flex: 1 1 0;+}++body.mobile .modal.options-dialog .modal-sidebar {+ height: auto;+ flex: 1 1 0;+ min-height: 0;+ border-bottom: none;+}++body.mobile .modal.options-dialog .modal-sidebar .settings-navigation {+ width: auto;+}++body.mobile .modal.options-dialog.mobile-view-list .modal-body {+ display: none;+}++body.mobile .modal.options-dialog.mobile-view-page .modal-sidebar {+ display: none;+}++/* In page view the back button + page title replace the static "Options" title. */+body.mobile .modal.options-dialog.mobile-view-page .modal-header > .modal-title {+ display: none;+}++.options-mobile-page-header {+ display: flex;+ align-items: center;+ gap: 4px;+ flex-grow: 1;+ min-width: 0;+}++.options-mobile-page-header .options-mobile-page-title {+ margin: 0;+ overflow: hidden;+ white-space: nowrap;+ text-overflow: ellipsis;+}diff --git a/apps/client/src/widgets/dialogs/OptionsDialog.tsx b/apps/client/src/widgets/dialogs/OptionsDialog.tsxindex 5dbe510f43..2236104fa0 100644--- a/apps/client/src/widgets/dialogs/OptionsDialog.tsx+++ b/apps/client/src/widgets/dialogs/OptionsDialog.tsx@@ -1,11 +1,13 @@import "./OptionsDialog.css";-import { useCallback, useContext, useRef, useState } from "preact/hooks";+import { useCallback, useContext, useEffect, useRef, useState } from "preact/hooks";import appContext from "../../components/app_context";import NoteContext from "../../components/note_context";import { t } from "../../services/i18n";+import utils from "../../services/utils";import NoteDetail from "../NoteDetail";+import ActionButton from "../react/ActionButton";import { useContainedLinkNavigation, useNoteContext, useTriliumEvent } from "../react/hooks";import Modal from "../react/Modal";import { NoteContextContext, ParentComponent } from "../react/react_utils";@@ -18,6 +20,9 @@ const DEFAULT_SECTION = "_optionsAppearance";* The settings dialog, opened via the `showOptions` command. Settings open in a dialog rather than* a hoisted tab (which confused users by seemingly hiding the note tree): the full-height sidebar* lists the settings pages while the body renders the active one through a dedicated note context.+ *+ * On mobile the sidebar and the page become a master-detail flow instead: the dialog first shows+ * only the list of pages, tapping one reveals it full-screen with a back button in the header.*/export default function OptionsDialog() {const [ shown, setShown ] = useState(false);@@ -26,7 +31,10 @@ export default function OptionsDialog() {// Remembers the page last viewed this session so reopening the dialog lands there instead of// always on Appearance. Kept in component state (resets on reload), not persisted.const [ lastSection, setLastSection ] = useState<string | null>(null);+ // Which half of the mobile master-detail flow is visible; has no effect on desktop.+ const [ mobileView, setMobileView ] = useState<"list" | "page">("list");const modalRef = useRef<HTMLDivElement>(null);+ const isMobile = utils.isMobile();useTriliumEvent("showOptions", async ({ section }) => {const noteContext = new NoteContext("_options-dialog");@@ -35,16 +43,27 @@ export default function OptionsDialog() {// Events triggered at note context level (e.g. the save indicator) would not work since the note context has no parent component. Propagate events to parent component so that they can be handled properly.noteContext.triggerEvent = (name, data) => parentComponent?.handleEventInChildren(name, data);setNoteContext(noteContext);+ // Requesting a specific section (e.g. "set up a password") skips the mobile master list.+ setMobileView(section ? "page" : "list");setShown(true);});+ // Bootstrap adds its own classes (e.g. `show`) to the modal element at runtime, so the+ // className prop must stay static — rewriting it from a render would wipe them and visually+ // dismiss the dialog. Toggle the mobile view class directly on the element instead.+ useEffect(() => {+ modalRef.current?.classList.toggle("mobile-view-list", mobileView === "list");+ modalRef.current?.classList.toggle("mobile-view-page", mobileView === "page");+ }, [ mobileView ]);+// Keep navigation between settings pages (sidebar entries, "Related settings" links) inside the// dialog; links to regular notes open in the quick-edit popup instead.useContainedLinkNavigation(modalRef, useCallback((notePath, viewScope) => {if (notePath.split("/").at(-1)?.startsWith("_options")) {void noteContext.setNote(notePath, { viewScope, keepActiveDialog: true });+ setMobileView("page");} else {- appContext.triggerCommand("openInPopup", { noteIdOrPath: notePath });+ void appContext.triggerCommand("openInPopup", { noteIdOrPath: notePath });}}, [ noteContext ]));@@ -53,6 +72,7 @@ export default function OptionsDialog() {<ModalmodalRef={modalRef}title={t("options.title")}+ header={isMobile && mobileView === "page" ? <MobilePageHeader onBack={() => setMobileView("list")} /> : undefined}sidebar={<SettingsSidebar />}customTitleBarButtons={[{iconClassName: "bx-expand-alt",@@ -92,3 +112,21 @@ function SettingsSidebar() {if (!noteId) return null;return <SettingsNavigation activeNoteId={noteId} />;}++/**+ * Replaces the "Options" title in the mobile page view: a back button returning to the master list+ * of pages, followed by the title of the page in view (the static title is hidden via CSS).+ */+function MobilePageHeader({ onBack }: { onBack: () => void }) {+ const { note } = useNoteContext();+ return (+ <div className="options-mobile-page-header">+ <ActionButton+ icon="bx bx-chevron-left"+ text={t("options.back")}+ onClick={onBack}+ />+ <h5 className="options-mobile-page-title">{note?.title}</h5>+ </div>+ );+}