Implement text input component (Task 9)

- Create TextInputSection component with large multiline textarea
- Add 'Next: Assign voices' button
- Implement text validation (non-empty)
- Show validation message for empty text
- Disable button when text is empty
- Update App.tsx to integrate TextInputSection
- Requirements: 1.1, 1.2, 1.3, 1.4
This commit is contained in:
2025-12-09 07:39:36 +00:00
parent 50d657f501
commit 85a71fac2c
2 changed files with 111 additions and 24 deletions

View File

@@ -1,34 +1,50 @@
import { useState } from 'react' import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css' import './App.css'
import TextInputSection from './components/TextInputSection'
function App() { function App() {
const [count, setCount] = useState(0) const [text, setText] = useState('')
const [phase, setPhase] = useState<'input' | 'assignment' | 'generated'>('input')
const [isLoading] = useState(false)
const handleTextChange = (newText: string) => {
setText(newText)
}
const handleNext = () => {
// TODO: Implement role detection and phase transition
console.log('Moving to voice assignment phase with text:', text)
setPhase('assignment')
}
return ( return (
<> <div className="min-h-screen bg-gray-50">
<div> <div className="container mx-auto py-8">
<a href="https://vite.dev" target="_blank"> <h1 className="text-4xl font-bold text-center mb-8">Text to Audiobook</h1>
<img src={viteLogo} className="logo" alt="Vite logo" />
</a> {phase === 'input' && (
<a href="https://react.dev" target="_blank"> <TextInputSection
<img src={reactLogo} className="logo react" alt="React logo" /> text={text}
</a> onChange={handleTextChange}
onNext={handleNext}
isLoading={isLoading}
disabled={false}
/>
)}
{phase === 'assignment' && (
<div className="text-center">
<p>Voice assignment phase (to be implemented)</p>
</div>
)}
{phase === 'generated' && (
<div className="text-center">
<p>Audio player phase (to be implemented)</p>
</div>
)}
</div> </div>
<h1>Vite + React</h1> </div>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
) )
} }

View File

@@ -0,0 +1,71 @@
import { useState } from 'react';
interface TextInputSectionProps {
text: string;
onChange: (text: string) => void;
onNext: () => void;
isLoading: boolean;
disabled: boolean;
}
export default function TextInputSection({
text,
onChange,
onNext,
isLoading,
disabled
}: TextInputSectionProps) {
const [showValidation, setShowValidation] = useState(false);
const handleNext = () => {
if (text.trim() === '') {
setShowValidation(true);
return;
}
setShowValidation(false);
onNext();
};
const handleTextChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
onChange(e.target.value);
if (e.target.value.trim() !== '') {
setShowValidation(false);
}
};
const isButtonDisabled = disabled || isLoading || text.trim() === '';
return (
<div className="w-full max-w-4xl mx-auto p-6">
<h2 className="text-2xl font-bold mb-4">Enter Your Text</h2>
<div className="mb-4">
<textarea
value={text}
onChange={handleTextChange}
placeholder="Enter your text here. Use patterns like 'Name:' or '[Name]' to mark different speakers..."
className="w-full h-96 p-4 border-2 border-gray-300 rounded-lg focus:border-blue-500 focus:outline-none resize-y text-base"
disabled={disabled || isLoading}
/>
</div>
{showValidation && text.trim() === '' && (
<div className="mb-4 p-3 bg-red-100 border border-red-400 text-red-700 rounded">
Please enter some text before proceeding.
</div>
)}
<button
onClick={handleNext}
disabled={isButtonDisabled}
className={`px-6 py-3 rounded-lg font-semibold text-white transition-colors ${
isButtonDisabled
? 'bg-gray-400 cursor-not-allowed'
: 'bg-blue-600 hover:bg-blue-700 cursor-pointer'
}`}
>
{isLoading ? 'Processing...' : 'Next: Assign voices'}
</button>
</div>
);
}