import { timestampDate } from "@bufbuild/protobuf/wkt"; import L, { DivIcon } from "leaflet"; import "leaflet.markercluster/dist/MarkerCluster.css"; import { ArrowUpRightIcon, MapPinIcon } from "lucide-react"; import { useEffect, useMemo } from "react"; import { MapContainer, Marker, Popup, useMap } from "react-leaflet"; import MarkerClusterGroup from "react-leaflet-cluster"; import { Link } from "react-router-dom"; import { defaultMarkerIcon, ThemedTileLayer } from "@/components/map/map-utils"; import { buildMemoCreatorFilter } from "@/helpers/resource-names"; import { useInfiniteMemos } from "@/hooks/useMemoQueries"; import { cn } from "@/lib/utils"; import { State } from "@/types/proto/api/v1/common_pb"; import { Memo } from "@/types/proto/api/v1/memo_service_pb"; interface Props { creator: string; className?: string; } interface ClusterGroup { getChildCount(): number; } const createClusterCustomIcon = (cluster: ClusterGroup) => { return new DivIcon({ html: `${cluster.getChildCount()}`, className: "border-none bg-transparent", iconSize: L.point(32, 32, true), }); }; const MapFitBounds = ({ memos }: { memos: Memo[] }) => { const map = useMap(); useEffect(() => { if (memos.length === 0) return; const validMemos = memos.filter((m) => m.location); if (validMemos.length === 0) return; const bounds = L.latLngBounds(validMemos.map((memo) => [memo.location!.latitude, memo.location!.longitude])); map.fitBounds(bounds, { padding: [50, 50] }); }, [memos, map]); return null; }; const UserMemoMap = ({ creator, className }: Props) => { const creatorFilter = useMemo(() => buildMemoCreatorFilter(creator), [creator]); const { data, isLoading } = useInfiniteMemos( { state: State.NORMAL, orderBy: "display_time desc", pageSize: 1000, filter: creatorFilter, }, { enabled: Boolean(creatorFilter) }, ); const memosWithLocation = useMemo(() => data?.pages.flatMap((page) => page.memos).filter((memo) => memo.location) || [], [data]); if (isLoading) return null; const defaultCenter = { lat: 48.8566, lng: 2.3522 }; return (
No location data found
Mapped memos
{memosWithLocation.length} places pinned