"use client"; import { useCallback, useEffect, useRef, useState } from "react"; import { Badge } from "@/components/ui/badge"; import type { GroupWithCount } from "@/types"; interface GroupBadgesProps { selectedGroupId: string | null; onGroupSelect: (groupId: string) => void; refreshTrigger?: number; groups: GroupWithCount[]; isLoading: boolean; } export function GroupBadges({ selectedGroupId, onGroupSelect, groups, isLoading, }: GroupBadgesProps) { const scrollContainerRef = useRef(null); const [showLeftFade, setShowLeftFade] = useState(false); const [showRightFade, setShowRightFade] = useState(false); const checkScrollPosition = useCallback(() => { const container = scrollContainerRef.current; if (!container) return; const { scrollLeft, scrollWidth, clientWidth } = container; setShowLeftFade(scrollLeft > 0); setShowRightFade(scrollLeft < scrollWidth - clientWidth - 1); }, []); useEffect(() => { const container = scrollContainerRef.current; if (!container) return; checkScrollPosition(); container.addEventListener("scroll", checkScrollPosition); const resizeObserver = new ResizeObserver(checkScrollPosition); resizeObserver.observe(container); return () => { container.removeEventListener("scroll", checkScrollPosition); resizeObserver.disconnect(); }; }, [checkScrollPosition]); if (isLoading && !groups.length) { return (
Loading groups...
); } return (
{showLeftFade && (
)} {showRightFade && (
)}
{groups.map((group) => ( { onGroupSelect( selectedGroupId === group.id ? "default" : group.id, ); }} > {group.name} {group.count} ))}
); }