"use client"; import { useRouter, useSearchParams } from "next/navigation"; import { useTransition } from "react"; import { cn } from "@/lib/utils"; const LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""); const NON_LATIN = "#"; export function LetterBar({ active, counts, }: { active: string | null; counts: Record; }) { const router = useRouter(); const params = useSearchParams(); const [, start] = useTransition(); const total = counts[""] ?? 0; const hasSearch = !!(params.get("q") ?? "").trim(); function go(letter: string | null) { const next = new URLSearchParams(params.toString()); if (letter == null) next.delete("letter"); else next.set("letter", letter); start(() => router.push(`?${next.toString()}`, { scroll: false })); } return (
{[...LETTERS, NON_LATIN].map((L) => { const n = counts[L] ?? 0; const enabled = n > 0 && !hasSearch; const isActive = active === L; return ( ); })}
); }