"use client"; import { useEffect, useRef } from "react"; import { cn } from "@/lib/utils"; import type { CategoryDTO } from "@/types/board"; /** * Mobile (< md) category rail: one chip per lane, shown under the top bar. * Doubles as the board's position indicator while swiping between lanes * (the active chip is highlighted, driven by the board's * IntersectionObserver) and as quick navigation -- tapping a chip glides * the lane pager to that lane. */ export function CategoryChips({ categories, activeCategoryId, onSelect, }: { categories: CategoryDTO[]; activeCategoryId: string | null; onSelect: (id: string) => void; }) { const chipRefs = useRef(new Map()); // Keep the active chip in view if the user swipes several lanes at once // (or a chip gets added/removed out of the strip's view). useEffect(() => { if (!activeCategoryId) return; chipRefs.current .get(activeCategoryId) ?.scrollIntoView({ behavior: "smooth", inline: "center", block: "nearest" }); }, [activeCategoryId]); return (
{categories.map((category) => { const active = category.id === activeCategoryId; const openTodos = category.groups.reduce( (n, g) => n + g.todos.filter((t) => !t.completed).length, 0 ); return ( ); })}
); }