mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-11-18 07:22:06 +00:00
replace cancel button with X use search params instead of path fix routes for filtering clubs by URL, add loading map spinner, remove useEffect normalised region name in url will set filter search region by url params add i8n to region filtering use jotai useSetAtom select value becomes the name of the region on selection fix geojson types fix region names apply same regional filtering logic to tournaments that we have for clubs type fixes for GeoJson Feature basic filtering of clubs by region working remove comments two column layout change text colours accept undefined in region data state selecting a region from modal sets state with region data of Feature type. Types currently not all correct. by region filter satisfies types, with no functionality yet remove unused imports add region option in dropdown rename file to reflect its function json file for region names comment out analytics script for testing loading upgrade mongo unformat file to keep line count small add json of French regions coordinates upgrade next to last v14
69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
"use client";
|
|
|
|
import { Feature, GeoJsonProperties, MultiPolygon, Polygon } from "geojson";
|
|
import { useSetAtom } from "jotai";
|
|
import { useHydrateAtoms } from "jotai/utils";
|
|
import dynamic from "next/dynamic";
|
|
import { useSearchParams } from "next/navigation";
|
|
|
|
import { clubsAtom, regionFilterAtom } from "@/atoms";
|
|
import LoadingMap from "@/components/LoadingMap";
|
|
import regionNames from "@/resources/regionNames.json";
|
|
import regionGeoJson from "@/resources/regionsGeoJson.json";
|
|
import { Club } from "@/types";
|
|
|
|
import ClubTable from "./ClubTable";
|
|
|
|
type ClubsDisplayProps = {
|
|
clubs: Club[];
|
|
};
|
|
|
|
/**
|
|
* Imports the club map component, ensuring CSR only.
|
|
* @remarks SSR is not supported by react-leaflet
|
|
*/
|
|
const ClubMap = dynamic(() => import("./ClubMap"), {
|
|
ssr: false,
|
|
loading: LoadingMap,
|
|
});
|
|
|
|
export default function ClubsDisplay({ clubs }: ClubsDisplayProps) {
|
|
useHydrateAtoms([[clubsAtom, clubs]]);
|
|
const setRegionFilter = useSetAtom(regionFilterAtom);
|
|
|
|
const searchParams = useSearchParams();
|
|
const regionSearchParam = searchParams.get("region");
|
|
|
|
if (regionSearchParam) {
|
|
const matchedRegion = regionNames.name.find(
|
|
(name) =>
|
|
name
|
|
.toLowerCase()
|
|
.replaceAll(" ", "-")
|
|
.normalize("NFD")
|
|
.replace(/[\u0300-\u036f]/g, "") === regionSearchParam.toLowerCase(),
|
|
);
|
|
|
|
const regionData = regionGeoJson.features.find(
|
|
(f) => f.properties.nom === matchedRegion,
|
|
);
|
|
|
|
if (regionData) {
|
|
setRegionFilter(
|
|
regionData as Feature<Polygon | MultiPolygon, GeoJsonProperties>,
|
|
);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<main className="relative grid h-full w-full lg:grid-cols-2">
|
|
<div>
|
|
<ClubMap />
|
|
</div>
|
|
<div className="relative bg-white dark:bg-gray-800 lg:overflow-y-auto">
|
|
<ClubTable />
|
|
</div>
|
|
</main>
|
|
);
|
|
}
|