"use client"; import { forwardRef, useMemo, useRef } from "react"; import { TimeControl, Tournament } from "@/types"; import L from "leaflet"; import { Marker, Popup, MarkerProps } from "react-leaflet"; import { useTranslations } from "next-intl"; import { useSetAtom } from "jotai"; import { FaTrophy } from "react-icons/fa"; import { last } from "lodash"; import { debouncedHoveredMapTournamentGroupIdAtom } from "@/app/atoms"; type TournamentMarkerProps = { tournamentGroup: Tournament[]; colour: string; } & Omit; export const TournamentMarker = forwardRef< L.Marker | null, TournamentMarkerProps >(({ tournamentGroup, colour, ...markerProps }, ref) => { const t = useTranslations("Tournaments"); const { date, latLng, groupId, timeControl } = tournamentGroup[0]; const setHoveredMapTournamentGroupId = useSetAtom( debouncedHoveredMapTournamentGroupIdAtom, ); const iconOptions = useMemo( () => new L.Icon({ iconUrl: `/images/leaflet/marker-icon-2x-${colour}.png`, shadowUrl: "/images/leaflet/marker-shadow.png", iconSize: [25, 41], iconAnchor: [12, 41], popupAnchor: [1, -34], shadowSize: [41, 41], timeControl, }), [colour, timeControl], ); const startDate = date; const endDate = last(tournamentGroup)!.date; return ( setHoveredMapTournamentGroupId(groupId), mouseout: () => setHoveredMapTournamentGroupId(null), }} {...markerProps} >
{date} {endDate !== startDate && ` - ${endDate}`}
{tournamentGroup.map((tournament) => ( {tournament.tournament} ))}
{tournamentGroup.some((t) => t.norm) && (
{t("norm")}
)} {t("approx")}
); }); TournamentMarker.displayName = "TournamentMarker";