Skip to content

Build your personal knowledge base with Trilium Notes

feat(geomap): show the marker as a dialog on a phone

Elian Doranc3e03ee1f332
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.css b/apps/client/src/widgets/collections/geomap/DetailPane.css
index 1d5acc5daa..4c426407c9 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.css
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.css
@@ -78,7 +78,8 @@
* to press: it is a line of text that happens to answer to a click, so it stands on no plate of its
* own until it is aimed at.
*/
-.geo-map-container .geo-detail-pane .geo-detail-pane-location {
+.geo-map-container .geo-detail-pane .geo-detail-pane-location,
+.modal.geo-detail-sheet .geo-detail-pane-location {
display: flex;
align-items: center;
gap: 6px;
@@ -99,3 +100,18 @@
}
}
+.modal.geo-detail-sheet .modal-dialog {
+ max-height: var(--tn-modal-max-height);
+ height: 100%;
+}
+
+.modal.geo-detail-sheet .modal-content {
+ overflow: hidden;
+}
+
+.modal.geo-detail-sheet .modal-body {
+ display: flex;
+ flex-direction: column;
+ min-height: 0;
+ overflow: auto;
+}
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
index d15130b901..0c5c009f0b 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
@@ -1157,4 +1157,52 @@ describe("DetailPane", () => {
expect(onMouseDown).not.toHaveBeenCalled();
expect(onKeyDown).not.toHaveBeenCalled();
});
+
+ /*
+ * A phone shows the marker as a dialog over the whole screen rather than as a pane beside the
+ * map (see MarkerSheet). A pane holding a whole note takes most of the screen there whatever is
+ * done to it, so the maximize that would give it the rest has nothing left to give — and the
+ * camera, which holds a marker clear of the pane, has no uncovered half to hold it in.
+ */
+ describe("on a phone", () => {
+ beforeEach(() => { window.glob.device = "mobile"; });
+ afterEach(() => { window.glob.device = "desktop"; });
+
+ async function openSheetFor(note: FNote, map: ReturnType<typeof fakeMap>) {
+ await mount([ note ], map);
+ map.setUnderPointer([ markerFeature(note, [ 2, 1 ]) ]);
+ await act(async () => map.click());
+ // The dialog goes up first and reads its note out of the context after, so what it
+ // holds is drawn a turn later than the pane's is.
+ await act(async () => {});
+ }
+
+ const sheet = () => document.querySelector(".modal.geo-detail-sheet");
+
+ it("shows the marker as a dialog rather than as a pane over the map", async () => {
+ const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });
+ await openSheetFor(note, fakeMap());
+
+ expect(pane()).toBeNull();
+ expect(sheet()).toBeTruthy();
+ // The same contents either way: the note, and what may be done with the marker.
+ expect(sheet()?.querySelector(".note-detail-stub")).toBeTruthy();
+ expect(sheet()?.querySelector(".geo-detail-pane-location")).toBeTruthy();
+ });
+
+ it("offers no maximize, the dialog already having the screen", async () => {
+ const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });
+ await openSheetFor(note, fakeMap());
+
+ expect(document.querySelector(".tn-embedded-note-maximize")).toBeNull();
+ });
+
+ it("leaves the camera alone, there being no pane to hold the marker clear of", async () => {
+ const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });
+ const map = fakeMap();
+ await openSheetFor(note, map);
+
+ expect(map.eased).toEqual([]);
+ });
+ });
});
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
index 7299796c6a..ec01d0784e 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
@@ -8,12 +8,14 @@ import FNote from "../../../entities/fnote";
import { copyTextWithToast } from "../../../services/clipboard_ext";
import { t } from "../../../services/i18n";
import link from "../../../services/link";
+import { isMobile } from "../../../services/utils";
import { announceEmbeddedNoteClosing, EmbeddedNoteActions, EmbeddedNoteScope, MaximizeAction, NoteColorAction, OpenNoteActions, SelectTitleOnFirstOpen, useEmbeddedNoteContext, useFollowLinksWithin } from "../../EmbeddedNotePane";
import TitleRow from "../../layout/TitleRow";
import NoteDetail from "../../NoteDetail";
import PromotedAttributes from "../../PromotedAttributes";
import ActionButton from "../../react/ActionButton";
import { useLegacyComponentElement, useNoteColorClass, useNoteLabel, useStaticTooltip } from "../../react/hooks";
+import Modal from "../../react/Modal";
import OverlayPanel, { OverlayPanelBody } from "../../react/OverlayPanel";
import { removeFromMap } from "./api";
import { GPX_MIME, trackHitLayers, trackSourceId } from "./GpxTrack";
@@ -170,11 +172,15 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, sel
// or only what the click named where it named more (see PaneFocus).
useEffect(() => {
if (!map || !note) return;
- // Nothing is aimed at behind a pane that covers the map: the camera would be moving to a
+ // Nothing is aimed at behind a surface that covers the map: the camera would be moving to a
// place nobody can see, and the move is seen — the map slides while the pane is still
// growing over it. Waiting instead is what makes the dependency below worth having, the
// pane coming back down being the moment the marker is worth framing again.
- if (maximized) return;
+ //
+ // A phone shows the marker as a dialog over the whole screen rather than as a pane beside
+ // the map (see MarkerSheet), so there is never a half of the map to hold it clear of: the
+ // camera has nothing to do there at all, and what it did was pan the map behind a sheet.
+ if (maximized || isMobile()) return;
if (note.mime === GPX_MIME) {
const focus = selection?.focus;
@@ -231,9 +237,10 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, sel
}, [ map, note?.noteId, location, selection?.focus, maximized ]);
// Bound only while something is selected, so the map's other Escape — giving up on placing a
- // marker (see index.tsx) — stands alone when nothing is.
+ // marker (see index.tsx) — stands alone when nothing is. A phone's dialog answers the key
+ // itself (see MarkerSheet), and two answers to one press would close it twice over.
useEffect(() => {
- if (!selection) return;
+ if (!selection || isMobile()) return;
const onKeyDown = (e: KeyboardEvent) => {
if (e.key === "Escape") {
@@ -256,11 +263,18 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, sel
// EmbeddedNotePane) — the map would otherwise rebind to the marker's note, tear the map
// down and take the WebGL context with it.
<EmbeddedNoteScope component={paneComponent} noteContext={noteContext}>
- <MarkerDetails
- note={note} parentNote={parentNote} isReadOnly={isReadOnly}
- maximized={maximized} onMaximizedChange={onMaximizedChange}
- onClose={closePane} onRelocate={relocate} onFollowLink={followLink}
- />
+ {isMobile() ? (
+ <MarkerSheet
+ note={note} parentNote={parentNote} isReadOnly={isReadOnly}
+ onClose={closePane} onRelocate={relocate} onFollowLink={followLink}
+ />
+ ) : (
+ <MarkerDetails
+ note={note} parentNote={parentNote} isReadOnly={isReadOnly}
+ maximized={maximized} onMaximizedChange={onMaximizedChange}
+ onClose={closePane} onRelocate={relocate} onFollowLink={followLink}
+ />
+ )}
{selection?.isNew && <SelectTitleOnFirstOpen />}
</EmbeddedNoteScope>
);
@@ -446,26 +460,85 @@ function MarkerDetails({ note, parentNote, isReadOnly, maximized, onMaximizedCha
{/* Grown over the map, the pane has a note's width, so what it holds is laid out for one
(see `tn-embedded-note-pane-wide` in EmbeddedNotePane.css). */}
<OverlayPanelBody className={clsx("geo-detail-pane-body tn-embedded-note-pane", maximized && "tn-embedded-note-pane-wide")}>
- <MarkerLocation note={note} />
-
- <MarkerActions note={note} parentNote={parentNote} isReadOnly={isReadOnly} onRelocate={onRelocate} />
+ <MarkerContents note={note} parentNote={parentNote} isReadOnly={isReadOnly} onRelocate={onRelocate} />
+ </OverlayPanelBody>
+ </OverlayPanel>
+ );
+}
- {/* Whatever fields the note's own definitions ask for, ahead of the note as the quick
- editor puts them — a marker is often a note whose type says less about it than
- its fields do. Nothing at all is shown for a note that promotes none.
+/**
+ * The marker as a phone shows it: the sheet the app raises its dialogs as, rather than a pane laid
+ * over the map. A pane holding a whole note takes most of a phone's screen whatever is done to it,
+ * so one drawn over the map leaves the map neither readable nor reachable — and the maximize that
+ * would give it the rest of the screen has nothing left to give. The note is shown as a note
+ * instead, and the map is left alone behind it (see the camera above).
+ *
+ * Dressed as the quick editor and the calendar's own sheet are, those being the app's ways of
+ * showing a whole note over whatever raised it (see the shared rules in PopupEditor.css).
+ *
+ * `show` is not a state because every way out of this dialog is also a way out of the selection:
+ * what answers `onHidden` clears it, and the sheet goes with it. Bootstrap is told to hide as the
+ * element leaves the tree, so nothing is left dimming the page behind it (see Modal).
+ */
+function MarkerSheet({ note, parentNote, isReadOnly, onClose, onRelocate, onFollowLink }: {
+ note: FNote;
+ parentNote: FNote;
+ isReadOnly: boolean;
+ onClose(): void;
+ onRelocate(): void;
+ onFollowLink(noteId: string): boolean;
+}) {
+ // Marked on the dialog rather than on its body, so that what heads it — the note's own title
+ // row, handed to the dialog — is inside the marked element too (see the pane above).
+ const modalRef = useRef<HTMLDivElement>(null);
+ useLegacyComponentElement(modalRef);
+ useFollowLinksWithin(modalRef, onFollowLink);
- The location is not among them, the line above naming it better: promoted, it is
- a box of raw digits standing beside a map of the very place it names, and the way
- to put a marker somewhere else here is to move it. */}
- <PromotedAttributes omit={[ LOCATION_ATTRIBUTE ]} />
+ return (
+ <Modal
+ className="geo-detail-sheet"
+ size="lg"
+ title={<TitleRow />}
+ modalRef={modalRef}
+ show
+ onHidden={onClose}
+ >
+ <div className="geo-detail-pane-body tn-embedded-note-pane">
+ <MarkerContents note={note} parentNote={parentNote} isReadOnly={isReadOnly} onRelocate={onRelocate} />
+ </div>
+ </Modal>
+ );
+}
- {/* The note itself, drawn by whichever widget its type calls for — the same one the
- quick editor mounts, so a marker is written in exactly as it is anywhere else.
- No toolbar stands beside it: the pane asks for the floating one, which the editor
- carries with it (see the view scope below). */}
- <NoteDetail />
- </OverlayPanelBody>
- </OverlayPanel>
+/** What is shown of the marker, under whatever heads it. Shared by the pane and the sheet, which
+ * differ only in what they put around this and how they are dismissed. */
+function MarkerContents({ note, parentNote, isReadOnly, onRelocate }: {
+ note: FNote;
+ parentNote: FNote;
+ isReadOnly: boolean;
+ onRelocate(): void;
+}) {
+ return (
+ <>
+ <MarkerLocation note={note} />
+
+ <MarkerActions note={note} parentNote={parentNote} isReadOnly={isReadOnly} onRelocate={onRelocate} />
+
+ {/* Whatever fields the note's own definitions ask for, ahead of the note as the quick
+ editor puts them — a marker is often a note whose type says less about it than
+ its fields do. Nothing at all is shown for a note that promotes none.
+
+ The location is not among them, the line above naming it better: promoted, it is
+ a box of raw digits standing beside a map of the very place it names, and the way
+ to put a marker somewhere else here is to move it. */}
+ <PromotedAttributes omit={[ LOCATION_ATTRIBUTE ]} />
+
+ {/* The note itself, drawn by whichever widget its type calls for — the same one the
+ quick editor mounts, so a marker is written in exactly as it is anywhere else.
+ No toolbar stands beside it: the pane asks for the floating one, which the editor
+ carries with it (see the view scope above). */}
+ <NoteDetail />
+ </>
);
}
diff --git a/apps/client/src/widgets/dialogs/PopupEditor.css b/apps/client/src/widgets/dialogs/PopupEditor.css
index a9ad3a8916..496724b476 100644
--- a/apps/client/src/widgets/dialogs/PopupEditor.css
+++ b/apps/client/src/widgets/dialogs/PopupEditor.css
@@ -35,13 +35,14 @@ body.mobile .modal.popup-editor-dialog .modal-dialog {
font-size: 1.1em;
}
-/* The note-title header (icon + editable title) is shared with the tree popup and the calendar's
- event sheet, which reuse the same TitleRow; keep the selectors together so the dialogs stay
- pixel-identical. This file is loaded wherever the app is: the quick editor keeps itself in the
- DOM and so is never lazily loaded (see layout_commons.tsx). */
+/* The note-title header (icon + editable title) is shared with the tree popup, the calendar's event
+ sheet and the geo map's marker sheet, which reuse the same TitleRow; keep the selectors together
+ so the dialogs stay pixel-identical. This file is loaded wherever the app is: the quick editor
+ keeps itself in the DOM and so is never lazily loaded (see layout_commons.tsx). */
.modal.popup-editor-dialog .modal-header .title-row,
.modal.tree-popup-editor-dialog .modal-header .title-row,
-.modal.calendar-event-sheet .modal-header .title-row {
+.modal.calendar-event-sheet .modal-header .title-row,
+.modal.geo-detail-sheet .modal-header .title-row {
flex-grow: 1;
display: flex;
align-items: center;
@@ -56,7 +57,8 @@ body.mobile .modal.popup-editor-dialog .modal-dialog {
.modal.popup-editor-dialog .modal-header .note-title-widget,
.modal.tree-popup-editor-dialog .modal-header .note-title-widget,
-.modal.calendar-event-sheet .modal-header .note-title-widget {
+.modal.calendar-event-sheet .modal-header .note-title-widget,
+.modal.geo-detail-sheet .modal-header .note-title-widget {
display: flex;
align-items: center;
}
@@ -86,14 +88,17 @@ body.mobile .modal.popup-editor-dialog .modal-dialog {
.modal.tree-popup-editor-dialog .title-row,
.modal.tree-popup-editor-dialog .note-icon-widget,
.modal.calendar-event-sheet .title-row,
-.modal.calendar-event-sheet .note-icon-widget {
+.modal.calendar-event-sheet .note-icon-widget,
+.modal.geo-detail-sheet .title-row,
+.modal.geo-detail-sheet .note-icon-widget {
height: 32px;
min-height: unset;
}
:root div.modal.popup-editor-dialog div.note-title-widget,
:root div.modal.tree-popup-editor-dialog div.note-title-widget,
-:root div.modal.calendar-event-sheet div.note-title-widget {
+:root div.modal.calendar-event-sheet div.note-title-widget,
+:root div.modal.geo-detail-sheet div.note-title-widget {
--note-title-padding-inline: 8px;
}
@@ -102,7 +107,9 @@ body.mobile .modal.popup-editor-dialog .modal-dialog {
.modal.tree-popup-editor-dialog .note-icon-widget button.note-icon,
.modal.tree-popup-editor-dialog .note-title-widget input.note-title,
.modal.calendar-event-sheet .note-icon-widget button.note-icon,
-.modal.calendar-event-sheet .note-title-widget input.note-title {
+.modal.calendar-event-sheet .note-title-widget input.note-title,
+.modal.geo-detail-sheet .note-icon-widget button.note-icon,
+.modal.geo-detail-sheet .note-title-widget input.note-title {
font-size: 1em;
}