import type { ShoppingListSummary } from '@superlist/shared' import { useQuery } from '@tanstack/react-query' import { Link } from '@tanstack/react-router' import { CheckIcon, ChevronDownIcon, ListIcon, StarIcon } from 'lucide-react' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' import { itemsQueryOptions } from '@/hooks/use-items' import { useLists } from '@/hooks/use-lists' import { useToday } from '@/hooks/use-today' import { splitItems } from '@/lib/items' type ListSwitcherProps = { list: Pick } /** * The open list's name with a "▾" that opens the user's lists (the same ones the * "Listas" tab shows), plus "X pendientes · Y comprados" below it. The primary list * opens on the home page, the others on their own page. */ export function ListSwitcher({ list }: ListSwitcherProps) { const { data: lists } = useLists() return (

{list.name} : cambiar de lista

Mis listas {lists?.map((option) => ( {option.isPrimary ? ( ) : ( )} ))} Ver todas las listas
) } function ListOption({ list, current }: { list: ShoppingListSummary; current: boolean }) { return ( <> {list.name} {list.isPrimary && } {current && } ) } /** "6 pendientes · 2 comprados", from the items query the page already loads. */ function ListCounts({ listId }: { listId: string }) { const { data: items } = useQuery(itemsQueryOptions(listId)) const today = useToday() if (!items) return null const { pending, boughtToday } = splitItems(items, today) return (

{pending.length} {pending.length === 1 ? 'pendiente' : 'pendientes'} · {boughtToday.length}{' '} {boughtToday.length === 1 ? 'comprado' : 'comprados'}

) }