diff --git a/apps/web/src/components/items/bought-item-list.tsx b/apps/web/src/components/items/bought-item-list.tsx index e675017..cb9d308 100644 --- a/apps/web/src/components/items/bought-item-list.tsx +++ b/apps/web/src/components/items/bought-item-list.tsx @@ -9,6 +9,7 @@ import { ItemRow } from './item-row' type BoughtItemListProps = { items: ListItem[] updateItem: ReturnType + savingIds: string[] } /** @@ -16,7 +17,7 @@ type BoughtItemListProps = { * default so marking an item visibly moves it down; the user can fold it. * Tapping an item here un-buys it and it returns to the pending list. */ -export function BoughtItemList({ items, updateItem }: BoughtItemListProps) { +export function BoughtItemList({ items, updateItem, savingIds }: BoughtItemListProps) { return ( @@ -27,7 +28,12 @@ export function BoughtItemList({ items, updateItem }: BoughtItemListProps) {
    {items.map((item) => ( - + ))}
diff --git a/apps/web/src/components/items/item-list.tsx b/apps/web/src/components/items/item-list.tsx index 91cc833..ffed105 100644 --- a/apps/web/src/components/items/item-list.tsx +++ b/apps/web/src/components/items/item-list.tsx @@ -4,7 +4,7 @@ import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert' import { Card, CardContent } from '@/components/ui/card' import { Separator } from '@/components/ui/separator' import { Skeleton } from '@/components/ui/skeleton' -import { useItems, useUpdateItem } from '@/hooks/use-items' +import { useItems, usePendingItemUpdates, useUpdateItem } from '@/hooks/use-items' import { useListEvents } from '@/hooks/use-list-events' import { useToday } from '@/hooks/use-today' import { ApiError } from '@/lib/api-client' @@ -25,6 +25,7 @@ type ItemListProps = { export function ItemList({ listId }: ItemListProps) { const { data: items, isPending, error } = useItems(listId) const updateItem = useUpdateItem(listId) + const savingIds = usePendingItemUpdates(listId) const today = useToday() // Live updates: another member adds or buys an item and this list refreshes. @@ -78,7 +79,12 @@ export function ItemList({ listId }: ItemListProps) { {pending.length > 0 && (
    {pending.map((item) => ( - + ))}
)} @@ -86,7 +92,7 @@ export function ItemList({ listId }: ItemListProps) { {boughtToday.length > 0 && ( <> {pending.length > 0 && } - + )} diff --git a/apps/web/src/components/items/item-row.tsx b/apps/web/src/components/items/item-row.tsx index 660374a..b5b25ec 100644 --- a/apps/web/src/components/items/item-row.tsx +++ b/apps/web/src/components/items/item-row.tsx @@ -9,10 +9,12 @@ import { cn } from '@/lib/utils' type ItemRowProps = { item: ListItem updateItem: ReturnType + /** This item's bought state is being saved; only this row waits for it. */ + isSaving: boolean } /** A single item row: tapping it toggles its bought state. */ -export function ItemRow({ item, updateItem }: ItemRowProps) { +export function ItemRow({ item, updateItem, isSaving }: ItemRowProps) { return (
  • @@ -21,7 +23,7 @@ export function ItemRow({ item, updateItem }: ItemRowProps) { type="button" aria-pressed={item.completed} // A placeholder has no server id yet, so it cannot be toggled. - disabled={updateItem.isPending || isOptimisticItem(item)} + disabled={isSaving || isOptimisticItem(item)} onClick={() => { updateItem.mutate({ itemId: item.id, completed: !item.completed }) // Back to the input, so the next item can be typed right away. diff --git a/apps/web/src/components/layout/app-header.tsx b/apps/web/src/components/layout/app-header.tsx index fb2da4f..a2ae881 100644 --- a/apps/web/src/components/layout/app-header.tsx +++ b/apps/web/src/components/layout/app-header.tsx @@ -1,8 +1,9 @@ import type { ShoppingListSummary } from '@superlist/shared' import { useQuery } from '@tanstack/react-query' import { Link, useMatch, useRouterState } from '@tanstack/react-router' -import { ArrowLeftIcon, SearchIcon, SettingsIcon } from 'lucide-react' +import { ArrowLeftIcon, SettingsIcon } from 'lucide-react' +import { sectionTitle } from '@/components/layout/nav-items' import { ThemeToggle } from '@/components/theme-toggle' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' @@ -13,13 +14,6 @@ import { listsQueryOptions, pickPrimaryList } from '@/hooks/use-lists' type HeaderList = Pick -function titleFor(pathname: string) { - if (pathname === '/') return 'Panel' - if (pathname.startsWith('/lists')) return 'Listas' - if (pathname.startsWith('/settings')) return 'Ajustes' - return 'Superlist' -} - export function AppHeader() { const pathname = useRouterState({ select: (state) => state.location.pathname }) const listMatch = useMatch({ from: '/_authenticated/lists/$listId/', shouldThrow: false }) @@ -47,19 +41,9 @@ export function AppHeader() { {list ? ( ) : ( -

    {titleFor(pathname)}

    +

    {sectionTitle(pathname)}

    )}
    - {list && ( - {saved && ( - Guardado localmente. - )} -
    - - - -
    - - - - Apariencia - Notificaciones y preferencias de visualización. - - - {[ - { - id: 'digest', - label: 'Resumen semanal', - hint: 'Un resumen de tus listas cada lunes.', - }, - { - id: 'mentions', - label: 'Menciones', - hint: 'Avísame cuando alguien mencione mi nombre.', - }, - ].map((option) => ( -
    -
    -

    {option.label}

    -

    {option.hint}

    -
    - -
    - ))} -
    -
    +
    + + @@ -129,3 +43,103 @@ function SettingsPage() {
    ) } + +const profileSchema = z.object({ + name: z.string().trim().min(1, 'El nombre es obligatorio').max(80, 'Máximo 80 caracteres'), +}) + +type ProfileValues = z.infer + +function ProfileCard() { + const { data: session } = useSession() + + const form = useForm({ + resolver: zodResolver(profileSchema), + defaultValues: { name: session?.user.name ?? '' }, + }) + + const onSubmit = form.handleSubmit(async (values) => { + const { error } = await authClient.updateUser({ name: values.name }) + + if (error) { + toast.error(error.message ?? 'No pudimos guardar tu nombre.') + return + } + + form.reset(values) + toast.success('Nombre actualizado.') + }) + + return ( + + + Perfil + Así te ven las personas con las que compartes listas. + + +
    + + + Nombre + + + + + + Correo electrónico + + + Lo usas para iniciar sesión y recibir invitaciones. + + + + + +
    +
    +
    + ) +} + +const THEME_OPTIONS: { value: Theme; label: string; icon: typeof SunIcon }[] = [ + { value: 'light', label: 'Claro', icon: SunIcon }, + { value: 'dark', label: 'Oscuro', icon: MoonIcon }, + { value: 'system', label: 'Sistema', icon: MonitorIcon }, +] + +function AppearanceCard() { + const { theme, setTheme } = useTheme() + + return ( + + + Apariencia + Elige el tema de la app en este dispositivo. + + +
    + Tema + {THEME_OPTIONS.map((option) => ( + + ))} +
    +
    +
    + ) +}