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): tint the marker preview with the note colour
Elian Doran042b45417f64
diff --git a/apps/client/src/widgets/collections/geomap/Tooltips.spec.tsx b/apps/client/src/widgets/collections/geomap/Tooltips.spec.tsxindex 722e926f49..d881485dff 100644--- a/apps/client/src/widgets/collections/geomap/Tooltips.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/Tooltips.spec.tsx@@ -213,6 +213,34 @@ describe("Tooltips", () => {expect(FakePopup.open[0]?.html).not.toContain("\n");});+ /**+ * The theme tints a preview through `.note-tooltip.with-hue`, off the hue carried by the note's+ * own colour class — so a preview built by hand has to wear that class or it is drawn plain,+ * however the note is coloured. The previews the tooltip service puts up get it for free (see+ * the template in note_tooltip.ts), which is what made this the odd one out.+ */+ it("tints the preview with the note's colour", async () => {+ const note = buildNote({ title: "Somewhere", "#geolocation": "1,2", "#color": "#ff0000" });+ const map = fakeMap();+ await mount(map);++ map.hover(note);+ await advance(500);+ expect(FakePopup.open[0]?.html).toContain(note.getColorClass());+ expect(note.getColorClass()).toContain("with-hue");+ });++ it("draws an uncoloured note's preview plain", async () => {+ const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });+ const map = fakeMap();+ await mount(map);++ map.hover(note);+ await advance(500);+ // No trailing space where the colour class would have gone.+ expect(FakePopup.open[0]?.html).toContain(`class="tooltip note-tooltip show"`);+ });+/*** `mouseenter` fires on entering the layer, not on entering a marker, so a pointer dragged from* one pin straight onto the next never leaves it — the first note's preview used to stay up overdiff --git a/apps/client/src/widgets/collections/geomap/Tooltips.tsx b/apps/client/src/widgets/collections/geomap/Tooltips.tsxindex 53ac7f7370..769ccfa2ac 100644--- a/apps/client/src/widgets/collections/geomap/Tooltips.tsx+++ b/apps/client/src/widgets/collections/geomap/Tooltips.tsx@@ -1,3 +1,4 @@+import clsx from "clsx";import { type Map as MapLibreGLMap, type MapGeoJSONFeature, type MapMouseEvent, Popup } from "maplibre-gl";import { useContext, useEffect } from "preact/hooks";@@ -113,10 +114,16 @@ export default function Tooltips({ selectedNoteId }: {// The read raced against the rest of the wait rather than run after it: the preview// holds to the full HOVER_DELAY however fast the note comes back, but a round trip no// longer stretches that wait unless it outlasts what is left of it.- const [ content ] = await Promise.all([- froca.getNote(noteId).then((note) => renderTooltip(note)),+ const [ rendered ] = await Promise.all([+ froca.getNote(noteId).then(async (note) => ({+ content: await renderTooltip(note),+ // The note's own colour, which the preview is tinted with exactly as the+ // tooltip service tints the ones it puts up itself (see note_tooltip.ts).+ colorClass: note?.getColorClass()+ })),new Promise((resolve) => setTimeout(resolve, HOVER_DELAY - READ_DELAY))]);+ const { content, colorClass } = rendered;// A note with no content and no path renders to nothing; the pointer may well have// moved on to another marker while this one was being read; and a click may have// dismissed the preview while it was still on its way (see dismiss).@@ -125,7 +132,7 @@ export default function Tooltips({ selectedNoteId }: {shown = noteId;tooltip.setLngLat(coordinates)- .setHTML(buildTooltipHtml(content))+ .setHTML(buildTooltipHtml(content, colorClass)).addTo(map);placePreview(map, tooltip, coordinates, selectedNoteId !== null);@@ -302,9 +309,12 @@ function placePreview(map: MapLibreGLMap, tooltip: Popup, coordinates: [ number,* Written without a line break anywhere between the tags, because `.tooltip-inner` is `pre-line`:* every newline inside it is a newline the preview is drawn with, and laying this out as one would* lay out markup put a blank line above the preview and another below it.+ *+ * @param colorClass the note's colour, which belongs on this same element: the theme tints a+ * preview through `.note-tooltip.with-hue`, off the hue the class carries.*/-function buildTooltipHtml(content: string) {- return `<div class="tooltip note-tooltip show" role="tooltip">`+function buildTooltipHtml(content: string, colorClass?: string) {+ return `<div class="${clsx("tooltip", "note-tooltip", "show", colorClass)}" role="tooltip">`+ `<div class="tooltip-inner">`+ `<div class="note-tooltip-content">${sanitizeNoteContentHtml(content)}</div>`+ `</div>`