'use client'; import { useActionState, useEffect, useRef, useState, type FC } from 'react'; import { useFormStatus } from 'react-dom'; import { convertTextToSpeech, type TtsState } from '@/app/actions'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Textarea } from '@/components/ui/textarea'; import { useToast } from '@/hooks/use-toast'; import { Volume2, LoaderCircle, Copy, Mic } from 'lucide-react'; const WindowControls = () => (
); interface TtsFormProps { examplePhrases: string[]; } function SubmitButton() { const { pending } = useFormStatus(); return ( ); } export const TtsForm: FC = ({ examplePhrases }) => { const initialState: TtsState = { success: false }; const [state, formAction] = useActionState(convertTextToSpeech, initialState); const { toast } = useToast(); const formRef = useRef(null); const [text, setText] = useState(''); useEffect(() => { if (state.error) { toast({ variant: 'destructive', title: 'Oops! Something went wrong.', description: state.error, }); } }, [state, toast]); const handleExampleClick = (phrase: string) => { setText(phrase); }; const handleCopyUrl = (url: string) => { navigator.clipboard.writeText(url).then(() => { toast({ title: 'Copied to clipboard!', description: 'Audio URL is ready to be shared.', }); }); }; return (
Text Input