diff --git a/src/app/sandbox/map/map-event-demo.tsx b/src/app/sandbox/map/map-event-demo.tsx index 3bfe170e..f5d8670d 100644 --- a/src/app/sandbox/map/map-event-demo.tsx +++ b/src/app/sandbox/map/map-event-demo.tsx @@ -7,7 +7,6 @@ import MapMarker from "@/components/map/map-marker"; function MapEventDemo() { const [position, setPosition] = useState<[number, number] | undefined>(); const map = useMapEvent("click", (e) => { - console.log(e.latlng); setPosition([e.latlng.lat, e.latlng.lng]); }); diff --git a/src/components/map/lazy-map-marker.tsx b/src/components/map/lazy-map-marker.tsx new file mode 100644 index 00000000..6094c3d8 --- /dev/null +++ b/src/components/map/lazy-map-marker.tsx @@ -0,0 +1,53 @@ +"use client"; + +import { Marker, Popup } from "react-leaflet"; +import L from "leaflet"; +import { ReactNode } from "react"; +import { useClientRenderToString } from "@/hooks/useClientRenderToString"; +import IconMarkerWall from "../ui/icons/marker-wall"; +import IconMarkerParking from "../ui/icons/marker-parking"; +import { IconSize } from "../ui/icons/icon-size"; + +type TLazyMapMarkerProps = { + type: "parking" | "wall"; + position: [number, number]; + popupContent?: ReactNode; + interactive?: boolean; + hidden?: boolean; +}; + +function LazyMapMarker({ + type, + position, + popupContent, + interactive = true, + hidden, +}: TLazyMapMarkerProps) { + const [icon] = useClientRenderToString( + type === "parking" ? ( + + ) : ( + + ) + ); + + return ( + + {popupContent && {popupContent}} + + ); +} + +export default LazyMapMarker; +export type { TLazyMapMarkerProps }; diff --git a/src/components/map/map-marker.tsx b/src/components/map/map-marker.tsx index 31aa44bd..6c6de148 100644 --- a/src/components/map/map-marker.tsx +++ b/src/components/map/map-marker.tsx @@ -1,49 +1,12 @@ -"use client"; +import dynamic from "next/dynamic"; +import { TLazyMapMarkerProps as TMapMarkerProps } from "./lazy-map-marker"; -import { Marker, Popup } from "react-leaflet"; -import L from "leaflet"; -import { ReactNode } from "react"; -import { useClientRenderToString } from "@/hooks/useClientRenderToString"; -import IconMarkerWall from "../ui/icons/marker-wall"; -import IconMarkerParking from "../ui/icons/marker-parking"; -import { IconSize } from "../ui/icons/icon-size"; +const LazyMapMarker = dynamic(() => import("./lazy-map-marker"), { + ssr: false, +}); -type TMapMarkerProps = { - type: "parking" | "wall"; - position: [number, number]; - popupContent?: ReactNode; - interactive?: boolean; -}; - -function MapMarker({ - type, - position, - popupContent, - interactive = true, -}: TMapMarkerProps) { - const [icon] = useClientRenderToString( - type === "parking" ? ( - - ) : ( - - ) - ); - - return ( - - {popupContent && {popupContent}} - - ); +function MapMarker(props: TMapMarkerProps) { + return ; } export default MapMarker; diff --git a/src/components/ui/coordinates-input.tsx b/src/components/ui/coordinates-input.tsx index afc37bf8..d5fde141 100644 --- a/src/components/ui/coordinates-input.tsx +++ b/src/components/ui/coordinates-input.tsx @@ -9,9 +9,9 @@ import Button from "./button"; import Dialog, { DialogSize, DialogTitleSize } from "./dialog"; import TextField, { TTextFieldProps } from "./text-field"; import { Dispatch, SetStateAction, useState } from "react"; +import IconMarker from "./icons/marker"; import { useMapEvent } from "react-leaflet"; import MapMarker from "../map/map-marker"; -import IconMarker from "./icons/marker"; type TCoordinatesInputProps = TTextFieldProps & { dialogTitle: string; @@ -120,10 +120,10 @@ function PlacedMarker({ setPosition([e.latlng.lat, e.latlng.lng]); }); - return ( - position && ( - - ) + return position ? ( + + ) : ( +