feat(items): voice dictation with Gemma 4 and a reworked list UI
Dictation: a mic button in the add field uses the Web Speech API (es-AR) and
shows the partial transcript in the input. POST /api/voice/split asks Gemma 4
(Gemini API, plain fetch) to split the sentence into one string per item,
written the way the existing parser reads typed text; each string then goes
through the usual add flow. The endpoint never fails because of the model:
missing key, timeout, 429 or invalid JSON fall back to splitting on commas,
semicolons, " y " and " e ". A toast offers "Deshacer" for the whole dictation;
if the request fails, the transcript is added as a single item.
UI: "+" instead of the search icon, quantity tags ("2 L", "×12", "1 kg"), the
list name with a list switcher and the pending/bought count in the header,
"Comprados (N)" folded by default, and a bottom sheet to edit name, quantity
(− / + and unit), note and delete. PATCH items now accepts a name.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,58 +1,63 @@
|
||||
import type { ListItem } from '@superlist/shared'
|
||||
import { ChevronDownIcon } from 'lucide-react'
|
||||
import { CheckIcon, ChevronDownIcon } from 'lucide-react'
|
||||
|
||||
import { Card } from '@/components/ui/card'
|
||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'
|
||||
import type { useUpdateItem } from '@/hooks/use-items'
|
||||
|
||||
import { ItemRow, type ItemRowProps } from './item-row'
|
||||
import { ItemRow } from './item-row'
|
||||
|
||||
type BoughtItemListProps = {
|
||||
items: ListItem[]
|
||||
updateItem: ReturnType<typeof useUpdateItem>
|
||||
savingIds: string[]
|
||||
/** The editing state of each row, owned by the parent so only one row edits at a time. */
|
||||
editingProps: (itemId: string) => Pick<ItemRowProps, 'editing' | 'onEditingChange'>
|
||||
onEdit: (item: ListItem) => void
|
||||
onMove: (item: ListItem) => void
|
||||
onDelete: (item: ListItem) => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapsible "Comprados" card below the pending items. Expanded by 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.
|
||||
* Collapsible "Comprados (N)" section at the end of the list, folded by default so
|
||||
* the pending items stay in focus. Tapping an item here un-buys it and it returns
|
||||
* to the pending list.
|
||||
*/
|
||||
export function BoughtItemList({
|
||||
items,
|
||||
updateItem,
|
||||
savingIds,
|
||||
editingProps,
|
||||
onEdit,
|
||||
onMove,
|
||||
onDelete,
|
||||
}: BoughtItemListProps) {
|
||||
return (
|
||||
<Collapsible defaultOpen asChild>
|
||||
<Card className="gap-0 py-0">
|
||||
<CollapsibleTrigger className="group bg-muted text-muted-foreground hover:text-foreground flex w-full items-center gap-3 px-4 py-3 text-left transition-colors">
|
||||
<ChevronDownIcon className="size-5 transition-transform group-data-[state=closed]:-rotate-90" />
|
||||
<span className="text-base">Comprados · {items.length}</span>
|
||||
<Collapsible asChild>
|
||||
<section className="border-border overflow-hidden rounded-xl border border-dashed">
|
||||
<CollapsibleTrigger className="group text-muted-foreground hover:text-foreground focus-visible:ring-ring/50 flex min-h-12 w-full items-center gap-3 px-4 py-3 text-left transition-colors outline-none focus-visible:ring-3">
|
||||
<CheckIcon className="text-primary size-4" strokeWidth={2.5} aria-hidden />
|
||||
<span className="flex-1 text-base">Comprados ({items.length})</span>
|
||||
<ChevronDownIcon
|
||||
className="size-5 transition-transform group-data-[state=open]:rotate-180"
|
||||
aria-hidden
|
||||
/>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent>
|
||||
<ul className="divide-y">
|
||||
{items.map((item) => (
|
||||
<ItemRow
|
||||
key={item.id}
|
||||
item={item}
|
||||
updateItem={updateItem}
|
||||
isSaving={savingIds.includes(item.id)}
|
||||
{...editingProps(item.id)}
|
||||
onMove={() => onMove(item)}
|
||||
onDelete={() => onDelete(item)}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
<Card className="gap-0 rounded-none border-x-0 border-b-0 py-0 shadow-none">
|
||||
<ul className="divide-y">
|
||||
{items.map((item) => (
|
||||
<ItemRow
|
||||
key={item.id}
|
||||
item={item}
|
||||
updateItem={updateItem}
|
||||
isSaving={savingIds.includes(item.id)}
|
||||
onEdit={() => onEdit(item)}
|
||||
onMove={() => onMove(item)}
|
||||
onDelete={() => onDelete(item)}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
</Card>
|
||||
</CollapsibleContent>
|
||||
</Card>
|
||||
</section>
|
||||
</Collapsible>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user