import { memo, useEffect, useRef, useState } from "react"; import { ChevronDown } from "lucide-react"; type Pick = { id: string; pickNumber: number; participant: { name: string }; sport: { name: string }; team: { name: string }; }; export const RecentPicksFeed = memo(function RecentPicksFeed({ picks }: { picks: Pick[] }) { const recentPicks = picks.slice(-3).toReversed(); const prevNewestIdRef = useRef(picks.at(-1)?.id); const [animatingId, setAnimatingId] = useState(undefined); const [isExpanded, setIsExpanded] = useState(true); useEffect(() => { const newest = recentPicks[0]; if (newest && newest.id !== prevNewestIdRef.current) { prevNewestIdRef.current = newest.id; setAnimatingId(newest.id); const t = setTimeout(() => setAnimatingId(undefined), 450); return () => clearTimeout(t); } }, [recentPicks]); return (
{isExpanded && (
{picks.length === 0 ? (

No picks yet

) : ( recentPicks.map((pick, index) => (
#{pick.pickNumber}
{pick.participant.name} {pick.sport.name}
{pick.team.name}
)) )}
)}
); });