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:
@@ -86,6 +86,8 @@ export function useCreateItem(listId: string) {
|
||||
|
||||
type UpdateItemInput = {
|
||||
itemId: string
|
||||
/** New name; omitted to leave it untouched. */
|
||||
name?: string
|
||||
/** New bought state; omitted when only the details are being changed. */
|
||||
completed?: boolean
|
||||
/** New quantity (`null` clears it); omitted to leave it untouched. */
|
||||
@@ -104,7 +106,13 @@ export function useUpdateItem(listId: string) {
|
||||
return useMutation({
|
||||
mutationKey,
|
||||
mutationFn: (input: UpdateItemInput) => {
|
||||
const body: { completed?: boolean; quantity?: string | null; notes?: string | null } = {}
|
||||
const body: {
|
||||
name?: string
|
||||
completed?: boolean
|
||||
quantity?: string | null
|
||||
notes?: string | null
|
||||
} = {}
|
||||
if (input.name !== undefined) body.name = input.name
|
||||
if (input.completed !== undefined) body.completed = input.completed
|
||||
if (input.quantity !== undefined) body.quantity = input.quantity
|
||||
if (input.notes !== undefined) body.notes = input.notes
|
||||
@@ -114,7 +122,7 @@ export function useUpdateItem(listId: string) {
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
},
|
||||
onMutate: async ({ itemId, completed, quantity, notes }) => {
|
||||
onMutate: async ({ itemId, name, completed, quantity, notes }) => {
|
||||
// Cancel the outgoing refetch so it cannot overwrite our optimistic one.
|
||||
await queryClient.cancelQueries({ queryKey })
|
||||
|
||||
@@ -126,6 +134,7 @@ export function useUpdateItem(listId: string) {
|
||||
|
||||
return {
|
||||
...item,
|
||||
...(name !== undefined ? { name: name.trim() } : {}),
|
||||
...(completed !== undefined
|
||||
? { completed, boughtAt: completed ? new Date().toISOString() : null }
|
||||
: {}),
|
||||
@@ -260,3 +269,28 @@ export function useDeleteItem(listId: string) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes items right away, without the undo window of `useDeleteItem`: used to undo a
|
||||
* dictation, which is itself the undo. The rows leave the list at once.
|
||||
*/
|
||||
export function useRemoveItems(listId: string) {
|
||||
const queryClient = useQueryClient()
|
||||
const { queryKey } = itemsQueryOptions(listId)
|
||||
|
||||
return async (itemIds: string[]) => {
|
||||
const ids = new Set(itemIds)
|
||||
queryClient.setQueryData(queryKey, (items) => items?.filter((item) => !ids.has(item.id)))
|
||||
|
||||
const results = await Promise.allSettled(
|
||||
itemIds.map((itemId) =>
|
||||
apiFetch<void>(`/lists/${listId}/items/${itemId}`, { method: 'DELETE' }),
|
||||
),
|
||||
)
|
||||
|
||||
if (results.some((result) => result.status === 'rejected')) {
|
||||
toast.error('No pudimos quitar todos los artículos.')
|
||||
await queryClient.invalidateQueries({ queryKey })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user