feat(web): UI quick wins for items, navigation and settings
- Toggling an item only disables that row, so several items can be marked in a row; failures roll back just that item and show a toast, and the list refetches once the last toggle settles. - Sidebar, bottom nav and header share one set of sections (Inicio / Listas / Ajustes); the bottom nav drops the duplicated "Cuenta" link and the header drops the non-functional search button. - Settings: the name is saved through BetterAuth, the email is shown read-only, and the fake notification switches are replaced by a real theme picker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import { ItemRow } from './item-row'
|
||||
type BoughtItemListProps = {
|
||||
items: ListItem[]
|
||||
updateItem: ReturnType<typeof useUpdateItem>
|
||||
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 (
|
||||
<Collapsible defaultOpen>
|
||||
<CollapsibleTrigger className="group flex w-full items-center gap-1.5 py-1 text-left">
|
||||
@@ -27,7 +28,12 @@ export function BoughtItemList({ items, updateItem }: BoughtItemListProps) {
|
||||
<CollapsibleContent>
|
||||
<ul className="flex flex-col gap-2 pt-2">
|
||||
{items.map((item) => (
|
||||
<ItemRow key={item.id} item={item} updateItem={updateItem} />
|
||||
<ItemRow
|
||||
key={item.id}
|
||||
item={item}
|
||||
updateItem={updateItem}
|
||||
isSaving={savingIds.includes(item.id)}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
</CollapsibleContent>
|
||||
|
||||
@@ -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 && (
|
||||
<ul className="flex flex-col gap-2">
|
||||
{pending.map((item) => (
|
||||
<ItemRow key={item.id} item={item} updateItem={updateItem} />
|
||||
<ItemRow
|
||||
key={item.id}
|
||||
item={item}
|
||||
updateItem={updateItem}
|
||||
isSaving={savingIds.includes(item.id)}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
@@ -86,7 +92,7 @@ export function ItemList({ listId }: ItemListProps) {
|
||||
{boughtToday.length > 0 && (
|
||||
<>
|
||||
{pending.length > 0 && <Separator className="mt-2" />}
|
||||
<BoughtItemList items={boughtToday} updateItem={updateItem} />
|
||||
<BoughtItemList items={boughtToday} updateItem={updateItem} savingIds={savingIds} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -9,10 +9,12 @@ import { cn } from '@/lib/utils'
|
||||
type ItemRowProps = {
|
||||
item: ListItem
|
||||
updateItem: ReturnType<typeof useUpdateItem>
|
||||
/** 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 (
|
||||
<li>
|
||||
<Card>
|
||||
@@ -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.
|
||||
|
||||
@@ -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<ShoppingListSummary, 'id' | 'name' | 'role' | 'isPrimary'>
|
||||
|
||||
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 ? (
|
||||
<ListHeading list={list} showBack={Boolean(listId)} />
|
||||
) : (
|
||||
<h1 className="truncate text-sm font-medium">{titleFor(pathname)}</h1>
|
||||
<h1 className="truncate text-sm font-medium">{sectionTitle(pathname)}</h1>
|
||||
)}
|
||||
<div className="ml-auto flex shrink-0 items-center gap-1">
|
||||
<button
|
||||
type="button"
|
||||
className="text-muted-foreground hover:bg-accent hover:text-accent-foreground mr-1 hidden items-center gap-2 rounded-md border px-3 py-1.5 text-xs md:flex"
|
||||
>
|
||||
<SearchIcon className="size-3.5" />
|
||||
Buscar
|
||||
<kbd className="bg-muted text-muted-foreground rounded px-1.5 py-0.5 font-mono text-[10px]">
|
||||
⌘K
|
||||
</kbd>
|
||||
</button>
|
||||
{list && (
|
||||
<Button variant="outline" size="sm" asChild>
|
||||
<Link to="/lists/$listId/settings" params={{ listId: list.id }}>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { Link, useRouterState } from '@tanstack/react-router'
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import { HomeIcon, SettingsIcon, ShoppingCartIcon } from 'lucide-react'
|
||||
|
||||
import { focusNewItemInput } from '@/components/items/create-item-form'
|
||||
import { isNavItemActive, NAV_ITEMS } from '@/components/layout/nav-items'
|
||||
import { NavUser } from '@/components/layout/nav-user'
|
||||
import {
|
||||
Sidebar,
|
||||
@@ -17,23 +15,6 @@ import {
|
||||
SidebarRail,
|
||||
} from '@/components/ui/sidebar'
|
||||
|
||||
type NavItem = {
|
||||
title: string
|
||||
to: string
|
||||
icon: LucideIcon
|
||||
}
|
||||
|
||||
const NAV_ITEMS: NavItem[] = [
|
||||
{ title: 'Principal', to: '/', icon: HomeIcon },
|
||||
{ title: 'Listas', to: '/lists', icon: ShoppingCartIcon },
|
||||
{ title: 'Ajustes', to: '/settings', icon: SettingsIcon },
|
||||
]
|
||||
|
||||
function isActive(pathname: string, to: string) {
|
||||
if (to === '/') return pathname === '/'
|
||||
return pathname === to || pathname.startsWith(`${to}/`)
|
||||
}
|
||||
|
||||
export function AppSidebar() {
|
||||
const pathname = useRouterState({ select: (state) => state.location.pathname })
|
||||
|
||||
@@ -59,13 +40,13 @@ export function AppSidebar() {
|
||||
|
||||
<SidebarContent>
|
||||
<SidebarGroup>
|
||||
<SidebarGroupLabel>Plataforma</SidebarGroupLabel>
|
||||
<SidebarGroupLabel>Navegación</SidebarGroupLabel>
|
||||
<SidebarMenu>
|
||||
{NAV_ITEMS.map((item) => (
|
||||
<SidebarMenuItem key={item.to}>
|
||||
<SidebarMenuButton
|
||||
asChild
|
||||
isActive={isActive(pathname, item.to)}
|
||||
isActive={isNavItemActive(pathname, item.to)}
|
||||
tooltip={item.title}
|
||||
>
|
||||
<Link
|
||||
|
||||
@@ -1,73 +1,34 @@
|
||||
import { Link, useRouterState } from '@tanstack/react-router'
|
||||
import { HomeIcon, SettingsIcon, ShoppingCartIcon, UserIcon } from 'lucide-react'
|
||||
|
||||
import { focusNewItemInput } from '@/components/items/create-item-form'
|
||||
import { isNavItemActive, NAV_ITEMS } from '@/components/layout/nav-items'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
function isActive(pathname: string, to: string) {
|
||||
if (to === '/') return pathname === '/'
|
||||
return pathname === to || pathname.startsWith(`${to}/`)
|
||||
}
|
||||
|
||||
export function BottomNav() {
|
||||
const pathname = useRouterState({ select: (state) => state.location.pathname })
|
||||
|
||||
return (
|
||||
<footer className="fixed inset-x-0 bottom-0 z-30 border-t bg-background/95 supports-[backdrop-filter]:bg-background/60 backdrop-blur md:hidden pb-[env(safe-area-inset-bottom)]">
|
||||
<nav className="mx-auto flex h-16 max-w-lg items-center justify-around px-2">
|
||||
<Link
|
||||
to="/"
|
||||
onClick={() => focusNewItemInput(pathname)}
|
||||
className={cn(
|
||||
'flex flex-col items-center gap-1 rounded-md px-2 py-1.5 text-xs transition-colors',
|
||||
isActive(pathname, '/')
|
||||
? 'text-foreground'
|
||||
: 'text-muted-foreground hover:text-foreground',
|
||||
)}
|
||||
>
|
||||
<HomeIcon className="size-5" />
|
||||
<span>Inicio</span>
|
||||
</Link>
|
||||
{NAV_ITEMS.map((item) => {
|
||||
const active = isNavItemActive(pathname, item.to)
|
||||
|
||||
<Link
|
||||
to="/lists"
|
||||
className={cn(
|
||||
'flex flex-col items-center gap-1 rounded-md px-2 py-1.5 text-xs transition-colors',
|
||||
isActive(pathname, '/lists')
|
||||
? 'text-foreground'
|
||||
: 'text-muted-foreground hover:text-foreground',
|
||||
)}
|
||||
>
|
||||
<ShoppingCartIcon className="size-5" />
|
||||
<span>Listas</span>
|
||||
</Link>
|
||||
|
||||
<Link
|
||||
to="/settings"
|
||||
className={cn(
|
||||
'flex flex-col items-center gap-1 rounded-md px-2 py-1.5 text-xs transition-colors',
|
||||
isActive(pathname, '/settings')
|
||||
? 'text-foreground'
|
||||
: 'text-muted-foreground hover:text-foreground',
|
||||
)}
|
||||
>
|
||||
<SettingsIcon className="size-5" />
|
||||
<span>Ajustes</span>
|
||||
</Link>
|
||||
|
||||
<Link
|
||||
to="/settings"
|
||||
className={cn(
|
||||
'flex flex-col items-center gap-1 rounded-md px-2 py-1.5 text-xs transition-colors',
|
||||
isActive(pathname, '/settings')
|
||||
? 'text-foreground'
|
||||
: 'text-muted-foreground hover:text-foreground',
|
||||
)}
|
||||
aria-label="Cuenta"
|
||||
>
|
||||
<UserIcon className="size-5" />
|
||||
<span>Cuenta</span>
|
||||
</Link>
|
||||
return (
|
||||
<Link
|
||||
key={item.to}
|
||||
to={item.to}
|
||||
onClick={item.to === '/' ? () => focusNewItemInput(pathname) : undefined}
|
||||
aria-current={active ? 'page' : undefined}
|
||||
className={cn(
|
||||
'flex flex-col items-center gap-1 rounded-md px-3 py-1.5 text-xs transition-colors',
|
||||
active ? 'text-foreground' : 'text-muted-foreground hover:text-foreground',
|
||||
)}
|
||||
>
|
||||
<item.icon className="size-5" />
|
||||
<span>{item.title}</span>
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</nav>
|
||||
</footer>
|
||||
)
|
||||
|
||||
25
apps/web/src/components/layout/nav-items.ts
Normal file
25
apps/web/src/components/layout/nav-items.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import { HomeIcon, SettingsIcon, ShoppingCartIcon } from 'lucide-react'
|
||||
|
||||
type NavItem = {
|
||||
title: string
|
||||
to: '/' | '/lists' | '/settings'
|
||||
icon: LucideIcon
|
||||
}
|
||||
|
||||
/** The app's sections, shared by the sidebar (desktop), the bottom nav (mobile) and the header. */
|
||||
export const NAV_ITEMS: NavItem[] = [
|
||||
{ title: 'Inicio', to: '/', icon: HomeIcon },
|
||||
{ title: 'Listas', to: '/lists', icon: ShoppingCartIcon },
|
||||
{ title: 'Ajustes', to: '/settings', icon: SettingsIcon },
|
||||
]
|
||||
|
||||
export function isNavItemActive(pathname: string, to: NavItem['to']) {
|
||||
if (to === '/') return pathname === '/'
|
||||
return pathname === to || pathname.startsWith(`${to}/`)
|
||||
}
|
||||
|
||||
/** Title of the section the pathname belongs to, for the header. */
|
||||
export function sectionTitle(pathname: string) {
|
||||
return NAV_ITEMS.find((item) => isNavItemActive(pathname, item.to))?.title ?? 'Superlist'
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import { ChevronsUpDownIcon, LogOutIcon, UserIcon } from 'lucide-react'
|
||||
import { ChevronsUpDownIcon, LogOutIcon, SettingsIcon } from 'lucide-react'
|
||||
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
|
||||
import {
|
||||
@@ -78,8 +78,8 @@ export function NavUser() {
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onClick={() => void navigate({ to: '/settings' })}>
|
||||
<UserIcon />
|
||||
Cuenta
|
||||
<SettingsIcon />
|
||||
Ajustes
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
Reference in New Issue
Block a user