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
fix(geomap): dress a marker's icon in its own colour, not the map's
Elian Dorane0940631261f
diff --git a/apps/client/src/stylesheets/theme-next-dark.css b/apps/client/src/stylesheets/theme-next-dark.cssindex f97a89a4b5..27254d3bb5 100644--- a/apps/client/src/stylesheets/theme-next-dark.css+++ b/apps/client/src/stylesheets/theme-next-dark.css@@ -416,6 +416,7 @@ body .todo-list input[type="checkbox"]:not(:checked):before {.note-split.with-hue,.quick-edit-dialog-wrapper.with-hue,+.geo-detail-pane.with-hue,.nested-note-list-item.with-hue,.note-book-card.with-hue .note-book-header,.ck-template-icon.with-hue {diff --git a/apps/client/src/stylesheets/theme-next-light.css b/apps/client/src/stylesheets/theme-next-light.cssindex d7df29c5ee..ef476ce3a6 100644--- a/apps/client/src/stylesheets/theme-next-light.css+++ b/apps/client/src/stylesheets/theme-next-light.css@@ -388,6 +388,7 @@.note-split.with-hue,.quick-edit-dialog-wrapper.with-hue,+.geo-detail-pane.with-hue,.nested-note-list-item.with-hue,.note-book-card.with-hue .note-book-header,.ck-template-icon.with-hue {diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.css b/apps/client/src/widgets/collections/geomap/DetailPane.cssindex 45c45ed5d4..2299aefc2d 100644--- a/apps/client/src/widgets/collections/geomap/DetailPane.css+++ b/apps/client/src/widgets/collections/geomap/DetailPane.css@@ -28,6 +28,22 @@z-index: 3;}+/*+ * A marker of no colour of its own wears none.+ *+ * The pane stands inside the map's note split, which carries the map note's colour, so the icon+ * would otherwise be dressed in a hue belonging to another note entirely — the very thing the+ * marker's own class overrides where it has one (see the `.geo-detail-pane.with-hue` rules in+ * theme-next-{light,dark}.css). `initial` rather than `unset`: these are inherited properties, so+ * unsetting them would let the split's values through again; made invalid, each `var()` falls back+ * to the plain icon colour it names.+ */+.geo-map-container .geo-detail-pane:not(.with-hue) {+ --note-icon-custom-color: initial;+ --note-icon-custom-background-color: initial;+ --note-icon-hover-custom-background-color: initial;+}+/** The app's own title row heads the pane (see TitleRow), so a note is renamed from a marker the way* it is renamed anywhere else. It brings no placing of its own, the shared panel giving that only todiff --git a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsxindex 1e1e372d34..dfd62b5869 100644--- a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx@@ -208,6 +208,38 @@ describe("DetailPane", () => {expect(heardByTheMap).not.toHaveBeenCalled();});+ /**+ * The icon in the title row is dressed by the hue of whatever carries the colour class around it+ * (see theme-next-{light,dark}.css). The pane stands inside the map's note split, which carries+ * the map note's colour, so without one of its own the marker wore the map's hue.+ */+ it("carries the marker's own colour, and none where it has no colour", async () => {+ buildNote({ id: "root", title: "root", children: [+ { id: "red", title: "Red", "#geolocation": "1,2", "#color": "#ff0000" },+ { id: "plain", title: "Plain", "#geolocation": "3,4" }+ ] });+ const red = froca.notes["red"];+ const plain = froca.notes["plain"];+ const map = fakeMap();+ await mount([ red, plain ], map);++ map.setUnderPointer([ markerFeature(red) ]);+ await act(async () => map.click());+ await settle();++ expect(pane()?.classList.contains("use-note-color")).toBe(true);+ expect(pane()?.classList.contains("with-hue")).toBe(true);+ expect(pane()?.className).toContain(red.getColorClass());++ // Switching markers is a note switch within a standing pane, so the colour has to follow it.+ map.setUnderPointer([ markerFeature(plain) ]);+ await act(async () => map.click());+ await settle();++ expect(pane()?.classList.contains("use-note-color")).toBe(false);+ expect(pane()?.classList.contains("with-hue")).toBe(false);+ });+/** The marker is brought to the middle of what the pane leaves uncovered, not of the map. */it("holds the marker it opens for clear of itself", async () => {const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsxindex 864e371a33..b954b1b9e4 100644--- a/apps/client/src/widgets/collections/geomap/DetailPane.tsx+++ b/apps/client/src/widgets/collections/geomap/DetailPane.tsx@@ -1,5 +1,6 @@import "./DetailPane.css";+import clsx from "clsx";import type { Map as MapLibreGLMap, MapMouseEvent } from "maplibre-gl";import { useCallback, useContext, useEffect, useState } from "preact/hooks";@@ -12,7 +13,7 @@ import link from "../../../services/link";import TitleRow from "../../layout/TitleRow";import NoteDetail from "../../NoteDetail";import ActionButton from "../../react/ActionButton";-import { useNoteLabel } from "../../react/hooks";+import { useNoteColorClass, useNoteLabel } from "../../react/hooks";import PromotedAttributes from "../../PromotedAttributes";import OverlayPanel, { OverlayPanelBody } from "../../react/OverlayPanel";import { NoteContextContext, ParentComponent } from "../../react/react_utils";@@ -164,9 +165,14 @@ function paneOffset(map: MapLibreGLMap): [number, number] {/** The pane itself, for a marker there is one to draw. */function MarkerDetails({ note, isReadOnly, onClose, onRelocate }: { note: FNote; isReadOnly: boolean; onClose(): void; onRelocate(): void }) {+ // The marker's own colour, which is what dresses its icon (see DetailPane.css) — as the quick+ // editor's wrapper carries it. Without it the pane would inherit the hue of the note split it+ // stands in, which is the map's colour and not the marker's.+ const colorClass = useNoteColorClass(note);+return (<OverlayPanel- className="geo-detail-pane"+ className={clsx("geo-detail-pane", colorClass)}header={<TitleRow compact />}close={{ text: t("geo-map.close-details"), onClick: onClose }}>