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
refactor(react/collections): move layer name to view
Elian Doran330b17bff829
diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsxindex c116ebd7a8..0a490b1f3e 100644--- a/apps/client/src/widgets/collections/geomap/index.tsx+++ b/apps/client/src/widgets/collections/geomap/index.tsx@@ -1,15 +1,21 @@import Map from "./map";import "./index.css";+import { ViewModeProps } from "../interface";+import { useNoteLabel } from "../../react/hooks";+import { DEFAULT_MAP_LAYER_NAME } from "./map_layer";const DEFAULT_COORDINATES: [number, number] = [3.878638227135724, 446.6630455551659];const DEFAULT_ZOOM = 2;-export default function GeoView() {+export default function GeoView({ note }: ViewModeProps) {+ const [ layerName ] = useNoteLabel(note, "map:style");+return (<div className="geo-view"><Mapcoordinates={DEFAULT_COORDINATES}zoom={DEFAULT_ZOOM}+ layerName={layerName ?? DEFAULT_MAP_LAYER_NAME}/></div>);diff --git a/apps/client/src/widgets/collections/geomap/map.tsx b/apps/client/src/widgets/collections/geomap/map.tsxindex 8a3dd97b15..4452be824a 100644--- a/apps/client/src/widgets/collections/geomap/map.tsx+++ b/apps/client/src/widgets/collections/geomap/map.tsx@@ -1,19 +1,17 @@import { useEffect, useRef, useState } from "preact/hooks";import L, { LatLng, Layer } from "leaflet";import "leaflet/dist/leaflet.css";-import { useNoteContext, useNoteLabel } from "../../react/hooks";-import { DEFAULT_MAP_LAYER_NAME, MAP_LAYERS } from "./map_layer";+import { MAP_LAYERS } from "./map_layer";interface MapProps {coordinates: LatLng | [number, number];zoom: number;+ layerName: string;}-export default function Map({ coordinates, zoom }: MapProps) {+export default function Map({ coordinates, zoom, layerName }: MapProps) {const mapRef = useRef<L.Map>(null);const containerRef = useRef<HTMLDivElement>(null);- const { note } = useNoteContext();- const [ layerName ] = useNoteLabel(note, "map:style");useEffect(() => {if (!containerRef.current) return;@@ -26,7 +24,7 @@ export default function Map({ coordinates, zoom }: MapProps) {const [ layer, setLayer ] = useState<Layer>();useEffect(() => {async function load() {- const layerData = MAP_LAYERS[layerName ?? DEFAULT_MAP_LAYER_NAME];+ const layerData = MAP_LAYERS[layerName];if (layerData.type === "vector") {const style = (typeof layerData.style === "string" ? layerData.style : await layerData.style());@@ -62,9 +60,5 @@ export default function Map({ coordinates, zoom }: MapProps) {mapRef.current.setView(coordinates, zoom);}, [ mapRef, coordinates, zoom ]);- return (- <div ref={containerRef} className="geo-map-container">-- </div>- );+ return <div ref={containerRef} className="geo-map-container" />;}