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:
71
frontend/src/components/TextInputSection.tsx
Normal file
71
frontend/src/components/TextInputSection.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user