"use client"; import { useEffect } from "react"; import { useTranslations } from "next-intl"; import { useAtomValue, useSetAtom, useAtom } from "jotai"; import { twMerge } from "tailwind-merge"; import { FaExternalLinkAlt } from "react-icons/fa"; import { FaTrophy } from "react-icons/fa"; import { Tooltip } from "react-tooltip"; import { filteredTournamentsListAtom, syncVisibleAtom, normsOnlyAtom, hoveredMapTournamentGroupIdAtom, debouncedHoveredMapTournamentGroupIdAtom, debouncedHoveredListTournamentIdAtom, } from "@/app/atoms"; import { useBreakpoint } from "@/hooks/tailwind"; import SearchBar from "./SearchBar"; import TimeControlFilters from "./TimeControlFilters"; import ScrollToTopButton from "./ScrollToTopButton"; export default function TournamentTable() { const t = useTranslations("Tournaments"); const filteredTournaments = useAtomValue(filteredTournamentsListAtom); const [syncVisible, setSyncVisible] = useAtom(syncVisibleAtom); const [normsOnly, setNormsOnly] = useAtom(normsOnlyAtom); const hoveredMapTournamentGroupId = useAtomValue( hoveredMapTournamentGroupIdAtom, ); const debouncedHoveredMapTournamentGroupId = useAtomValue( debouncedHoveredMapTournamentGroupIdAtom, ); const setHoveredListTournamentId = useSetAtom( debouncedHoveredListTournamentIdAtom, ); const isLg = useBreakpoint("lg"); useEffect(() => { if (!isLg || debouncedHoveredMapTournamentGroupId === null) return; const tournamentRow = document.querySelector( `[data-group-id="${debouncedHoveredMapTournamentGroupId}"]`, ); tournamentRow?.scrollIntoView({ behavior: "smooth" }); }, [debouncedHoveredMapTournamentGroupId, isLg]); return (
{filteredTournaments.length === 0 ? ( ) : ( filteredTournaments.map((tournament) => ( setHoveredListTournamentId(tournament.id)} onMouseLeave={() => setHoveredListTournamentId(null)} className={twMerge( "scroll-m-20 bg-white text-gray-900 hover:bg-gray-200 dark:bg-gray-800 dark:text-white dark:hover:bg-gray-900", hoveredMapTournamentGroupId === `${tournament.groupId}_${tournament.timeControl}` && "bg-gray-200 dark:bg-gray-900", )} > )) )}
{t("date")} {t("town")} {t("tournament")} {t("timeControl")}
{t("noneFound")}
{tournament.date} {tournament.town} {tournament.norm && ( )} {tournament.tournament} {t("timeControlEnum", { tc: tournament.timeControl })}
{t("norm")}
); }