An empty list dictates from its central card; once it has items that card is gone, so the same flow now has a floating microphone in the bottom-right corner that opens a bottom sheet and starts listening in the same tap. - use-dictate-items extracts the dictation wiring shared by the card and the sheet (split by the API, merged with pending items, undoable toast). - DictationFeedback keeps the live state (listening, phrases heard, errors) the same in both surfaces. - Closing the sheet ends the dictation like "Detener": what was heard is added. - canDictate() centralises the "an iOS home-screen app cannot dictate" rule; the sheet offers "Escribir a mano" there and focuses the composer input.
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { Loader2Icon, MicIcon, SquareIcon } from 'lucide-react'
|
|
|
|
import { DictationFeedback } from '@/components/items/dictation-feedback'
|
|
import { Button } from '@/components/ui/button'
|
|
import { useDictateItems } from '@/hooks/use-dictate-items'
|
|
|
|
type DictateItemsButtonProps = {
|
|
listId: string
|
|
}
|
|
|
|
/**
|
|
* "Dictar ítems" for an empty list: listens until the user stops it and adds what was
|
|
* said through the same flow as the input's microphone (split by the API, undoable).
|
|
*/
|
|
export function DictateItemsButton({ listId }: DictateItemsButtonProps) {
|
|
const { listening, busy, processing, heard, message, start, stop } = useDictateItems(listId)
|
|
|
|
const label = processing
|
|
? 'Procesando el dictado'
|
|
: listening
|
|
? 'Detener dictado'
|
|
: 'Dictar ítems'
|
|
|
|
return (
|
|
<div className="flex flex-col items-center gap-2">
|
|
<Button
|
|
type="button"
|
|
variant={listening ? 'default' : 'secondary'}
|
|
aria-label={label}
|
|
aria-pressed={listening}
|
|
disabled={busy}
|
|
className="relative rounded-full"
|
|
onClick={() => {
|
|
if (listening) stop()
|
|
else start()
|
|
}}
|
|
>
|
|
{busy ? (
|
|
<Loader2Icon className="animate-spin" />
|
|
) : listening ? (
|
|
<SquareIcon className="fill-current" />
|
|
) : (
|
|
<MicIcon />
|
|
)}
|
|
{listening ? 'Detener dictado' : 'Dictar ítems'}
|
|
</Button>
|
|
|
|
<DictationFeedback listening={listening} heard={heard} message={message} />
|
|
</div>
|
|
)
|
|
}
|