Files
echecsfrance/src/app/[locale]/(main)/components/MapCoordinateSelection.tsx
T
owenrees feadb465eb upgrade Nodemailer to v10
fix dead code with knip

upgrade TS to v6 and fix linting errors

auto apply oxfmt rules

fix linting errors - unused deps etc

ignore file

remove all ignored files in knip

add knip - dead code analysis tool

swap prettier and eslint of oxfmt and oxlint

fix: fix map rendering in react strict mode

fix: headlessUI float replace

fix: disable Matomo if not URL and SITE ID exist

upgrade: 1st pass upgrade to Next.js v16

deps: upgrade react to v19
2026-10-05 16:15:25 +02:00

75 lines
2.1 KiB
TypeScript

"use client";
import { useMemo, useRef } from "react";
import { useSetAtom } from "jotai";
import L, { LatLngLiteral } from "leaflet";
import "leaflet-defaulticon-compatibility";
import "leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.css";
import "leaflet/dist/leaflet.css";
import { useFormContext, useWatch } from "react-hook-form";
import { MapContainer, Marker, TileLayer } from "react-leaflet";
import { mapBoundsAtom } from "@/atoms";
import { MapEvents } from "@/components/MapEvents";
const center: LatLngLiteral = { lat: 47.0844, lng: 2.3964 };
const MapCoordinateSelection = ({ page }: { page: "club" | "tournament" }) => {
const { control, setValue } = useFormContext();
const latValue = useWatch({ control, name: `${page}.coordinates.0` });
const lngValue = useWatch({ control, name: `${page}.coordinates.1` });
const setMapBounds = useSetAtom(mapBoundsAtom);
const markerRef = useRef<L.Marker | null>(null);
const eventHandlers = useMemo(
() => ({
dragend() {
const marker = markerRef.current;
if (marker != null) {
const position = marker.getLatLng();
setValue(
`${page}.coordinates.0`,
Math.round((position.lat + Number.EPSILON) * 10000) / 10000,
);
setValue(
`${page}.coordinates.1`,
Math.round((position.lng + Number.EPSILON) * 10000) / 10000,
);
}
},
}),
[setValue, page],
);
return (
<MapContainer
center={center}
zoom={5}
scrollWheelZoom={false}
style={{ height: "600px", flexGrow: 1 }}
ref={(map) => {
if (map) {
setMapBounds(map.getBounds());
}
}}
>
<MapEvents />
<TileLayer
attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<Marker
position={{ lat: latValue, lng: lngValue }}
draggable={true}
ref={markerRef}
eventHandlers={eventHandlers}
/>
</MapContainer>
);
};
export default MapCoordinateSelection;