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(client): show the note map in a modal on mobile
Elian Doran749b03f08127
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.tsindex 95ad3d8cc1..c5b3c1c9c3 100644--- a/apps/client/src/components/app_context.ts+++ b/apps/client/src/components/app_context.ts@@ -163,6 +163,8 @@ export type CommandMappings = {showLeftPane: CommandData;showAttachments: CommandData;showNoteAttributes: CommandData;+ /** Shows the note map as a modal, for the layouts with no right pane to put it in. */+ showNoteMap: CommandData;showSearchHistory: CommandData;showShareSubtree: CommandData;hoistNote: CommandData & { noteId: string };diff --git a/apps/client/src/components/root_command_executor.ts b/apps/client/src/components/root_command_executor.tsindex 7f341b22f4..1318618264 100644--- a/apps/client/src/components/root_command_executor.ts+++ b/apps/client/src/components/root_command_executor.ts@@ -196,6 +196,14 @@ export default class RootCommandExecutor extends Component {}async toggleRibbonTabNoteMapCommand(data: CommandListenerData<"toggleRibbonTabNoteMap">) {+ // A phone has neither the ribbon the map was a tab of nor the pane it is a card of, so the menu+ // it is asked from is where it is asked from and a modal is where it is shown — as the note's+ // attributes, its backlinks and its paths already are.+ if (utils.isMobile()) {+ this.triggerEvent("showNoteMap", data);+ return;+ }+const { isExperimentalFeatureEnabled } = await import("../services/experimental_features.js");const isNewLayout = isExperimentalFeatureEnabled("new-layout");if (!isNewLayout) {diff --git a/apps/client/src/layouts/layout_commons.tsx b/apps/client/src/layouts/layout_commons.tsxindex 907197bb46..169ffc73d3 100644--- a/apps/client/src/layouts/layout_commons.tsx+++ b/apps/client/src/layouts/layout_commons.tsx@@ -38,6 +38,8 @@ export function applyModals(rootContainer: RootContainer) {.child(<LazyDialog triggerEvents={["showOptions"]} loader={() => import("../widgets/dialogs/OptionsDialog.jsx")} />).child(<LazyDialog triggerEvents={["showOcrTextDialog"]} loader={() => import("../widgets/dialogs/ocr_text.js")} />).child(<LazyDialog triggerEvents={["showNoteAttributes"]} loader={() => import("../widgets/dialogs/note_attributes.jsx")} />)+ // Lazily loaded above all: the map is drawn by force-graph, kept out of the boot bundle.+ .child(<LazyDialog triggerEvents={["showNoteMap"]} loader={() => import("../widgets/dialogs/note_map.jsx")} />).child(<LazyDialog triggerEvents={["showUploadAttachmentsDialog"]} loader={() => import("../widgets/dialogs/upload_attachments.js")} />).child(<LazyDialog triggerEvents={["openInTreePopup"]} loader={() => import("../widgets/dialogs/TreePopupEditor.jsx")} />)// The following three are deliberately eager (not wrapped in LazyDialog):diff --git a/apps/client/src/widgets/dialogs/note_map.css b/apps/client/src/widgets/dialogs/note_map.cssnew file mode 100644index 0000000000..53251f2d43--- /dev/null+++ b/apps/client/src/widgets/dialogs/note_map.css@@ -0,0 +1,25 @@+.modal.note-map-modal {+ .modal-body {+ /* The map is drawn to whatever box it is given and keeps to it, so the body is a frame around+ it rather than a page to scroll. */+ padding: 0;+ display: flex;+ flex-direction: column;+ }++ .note-map-modal-body {+ /* Anchors the map's floating buttons (map type, fix nodes), same as the ribbon wrapper. */+ position: relative;+ flex: 1;+ /* A modal that is not the whole screen is as tall as what is in it, so the map has to bring a+ height of its own; where it is the whole screen the rule below hands that back. */+ min-height: 70vh;+ overflow: hidden;+ }+}++/* The whole screen leaves the map what the header does not take, rather than a share of the viewport+ measured without it — which would overflow the modal by the height of its own title. */+body.mobile .modal.note-map-modal .modal-dialog-full-page-on-mobile .note-map-modal-body {+ min-height: 0;+}diff --git a/apps/client/src/widgets/dialogs/note_map.tsx b/apps/client/src/widgets/dialogs/note_map.tsxnew file mode 100644index 0000000000..88fee281e5--- /dev/null+++ b/apps/client/src/widgets/dialogs/note_map.tsx@@ -0,0 +1,51 @@+import "./note_map.css";++import { useRef, useState } from "preact/hooks";++import { t } from "../../services/i18n";+import NoteMap from "../note_map/NoteMap";+import { useActiveNoteContext, useTriliumEvent } from "../react/hooks";+import Modal from "../react/Modal";++/**+ * The note map as a modal, for the layouts with no right pane to put it in — the mobile one, where it+ * is summoned from the note's own menu. The map follows the note being read, so the modal is summoned+ * without being told which note it is about.+ *+ * Drawn as the connections card's map expanded is drawn, which is what this is a phone's answer to:+ * the same two maps to choose between, remembered the same way.+ */+export default function NoteMapDialog() {+ const [ shown, setShown ] = useState(false);++ useTriliumEvent("showNoteMap", () => setShown(true));++ return (+ <Modal+ className="note-map-modal"+ // Named as the menu entry that summons it names it.+ title={t("note_map.title")}+ size="lg"+ show={shown}+ onHidden={() => setShown(false)}+ isFullPageOnMobile+ >+ <NoteMapBody />+ </Modal>+ );+}++function NoteMapBody() {+ const { note } = useActiveNoteContext();+ const containerRef = useRef<HTMLDivElement>(null);++ if (!note) {+ return null;+ }++ return (+ <div class="note-map-modal-body" ref={containerRef}>+ <NoteMap note={note} widgetMode="expanded" parentRef={containerRef} />+ </div>+ );+}