Files
superlist/apps/web/src/hooks/use-voice-split.ts
Jose Selesan a814b34036 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>
2026-10-28 19:25:10 -03:00

21 lines
699 B
TypeScript

import type { VoiceSplitRequest, VoiceSplitResponse } from '@superlist/shared'
import { useMutation } from '@tanstack/react-query'
import { apiFetch } from '@/lib/api-client'
/**
* Asks the API to split a dictated sentence into one string per item, each written the
* way the item parser reads typed text. The API never fails because of the model (it
* falls back to splitting on commas and "y"), so an error here means the request did not
* get through.
*/
export function useVoiceSplit() {
return useMutation({
mutationFn: (input: VoiceSplitRequest) =>
apiFetch<VoiceSplitResponse>('/voice/split', {
method: 'POST',
body: JSON.stringify(input),
}),
})
}