"use client"; import { useTranslations } from "next-intl"; import { useAtomValue, useSetAtom } from "jotai"; import { twMerge } from "tailwind-merge"; import { filteredTournamentsAtom, hoveredMapTournamentIdAtom, debouncedHoveredMapTournamentIdAtom, debouncedHoveredListTournamentIdAtom, } from "@/app/atoms"; import SearchBar from "./SearchBar"; import ScrollToTopButton from "./ScrollToTopButton"; import { useEffect } from "react"; export default function TournamentTable() { const t = useTranslations("Tournaments"); const filteredTournaments = useAtomValue(filteredTournamentsAtom); const hoveredMapTournamentId = useAtomValue(hoveredMapTournamentIdAtom); const debouncedHoveredMapTournamentId = useAtomValue( debouncedHoveredMapTournamentIdAtom ); const setHoveredListTournamentId = useSetAtom( debouncedHoveredListTournamentIdAtom ); useEffect(() => { if (debouncedHoveredMapTournamentId === null) return; const tournamentRow = document.getElementById( debouncedHoveredMapTournamentId ); tournamentRow?.scrollIntoView({ behavior: "smooth" }); }, [debouncedHoveredMapTournamentId]); 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", hoveredMapTournamentId === tournament._id && "bg-gray-200 dark:bg-gray-900" )} > )) )}
{t("date")} {t("town")} {t("tournament")} {t("timeControl")}
{t("noneFound")}
{tournament.date} {tournament.town} {tournament.tournament} {tournament.time_control}
); }