Files
echecsfrance/src/app/[locale]/(main)/tournaments/TournamentMap.tsx
T
owenrees da78e82a44 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-09-29 22:16:07 +02:00

91 lines
2.7 KiB
TypeScript

"use client";
import { useCallback, useMemo } from "react";
import { useAtomValue } from "jotai";
import L from "leaflet";
import "leaflet-defaulticon-compatibility";
import "leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.css";
import "leaflet.smooth_marker_bouncing";
import "leaflet/dist/leaflet.css";
import { countBy, groupBy } from "lodash";
import { filteredTournamentsByTimeControlAndZoneAtom, normsOnlyAtom } from "@/atoms";
import { Map, MapMarker } from "@/components/Map";
import { TimeControlColours } from "@/constants";
import { TimeControl } from "@/types";
import { generatePieSVG } from "@/utils/pie";
import Legend from "./Legend";
import TimeControlFilters from "./TimeControlFilters";
import { TournamentMarker } from "./TournamentMarker";
const TournamentMap = () => {
const tournaments = useAtomValue(filteredTournamentsByTimeControlAndZoneAtom);
const normsOnly = useAtomValue(normsOnlyAtom);
const filteredTournaments = useMemo(
() => tournaments.filter((t) => (normsOnly ? t.norm : true)),
[normsOnly, tournaments],
);
const groupedTournaments = groupBy(filteredTournaments, (t) => t.groupId);
const createClusterCustomIcon = useCallback((cluster: any) => {
const childCount = cluster.getChildCount();
const children = cluster.getAllChildMarkers();
// We added the time control as the class name when creating the marker
const timeControlCounts = countBy(
children,
(child: any) => child.options.icon.options.className,
);
const html = `
<div>
${generatePieSVG(
"absolute w-[30px]",
15,
[TimeControl.Classic, TimeControl.Rapid, TimeControl.Blitz, TimeControl.Other].map(
(tc) => ({
value: timeControlCounts[tc] ?? 0,
colour: TimeControlColours[tc],
}),
),
)}
<span class="text-white font-semibold relative z-[300]">${childCount}</span>
</div>
`;
return new L.DivIcon({
html,
className: "marker-cluster bg-gray-600/20",
iconSize: new L.Point(40, 40),
});
}, []);
const markers: MapMarker[] = useMemo(
() =>
Object.values(groupedTournaments).map((tournamentGroup) => {
const { groupId } = tournamentGroup[0];
return {
markerId: groupId,
tableIds: tournamentGroup.map((t) => t.id),
component: <TournamentMarker key={groupId} tournamentGroup={tournamentGroup} />,
};
}),
[groupedTournaments],
);
return (
<Map
markers={markers}
legend={<Legend />}
filters={<TimeControlFilters />}
iconCreateFunction={createClusterCustomIcon}
/>
);
};
export default TournamentMap;