diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index a4c1c82..4b7d9c9 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -103,6 +103,49 @@ function App() { ) } + const handleSegmentTextChange = (segmentId: string, newText: string) => { + setScriptSegments(prev => + prev.map(segment => + segment.id === segmentId + ? { ...segment, text: newText } + : segment + ) + ) + } + + const handleSegmentSplit = (segmentId: string, splitPosition: number) => { + setScriptSegments(prev => { + const segmentIndex = prev.findIndex(s => s.id === segmentId) + if (segmentIndex === -1) return prev + + const segment = prev[segmentIndex] + const firstPart = segment.text.substring(0, splitPosition).trim() + const secondPart = segment.text.substring(splitPosition).trim() + + if (!firstPart || !secondPart) return prev + + // Create new segments + const newSegments = [...prev] + newSegments[segmentIndex] = { + ...segment, + text: firstPart + } + + // Insert second part after the first + newSegments.splice(segmentIndex + 1, 0, { + id: `${segmentId}-split-${Date.now()}`, + speaker: segment.speaker, // Keep same speaker by default + text: secondPart + }) + + return newSegments + }) + } + + const handleSegmentDelete = (segmentId: string) => { + setScriptSegments(prev => prev.filter(segment => segment.id !== segmentId)) + } + const handleGenerate = async () => { setIsGenerating(true) setError(null) @@ -265,6 +308,9 @@ function App() { segments={scriptSegments} roles={roles} onSegmentChange={handleSegmentChange} + onSegmentTextChange={handleSegmentTextChange} + onSegmentSplit={handleSegmentSplit} + onSegmentDelete={handleSegmentDelete} onGenerate={handleGenerate} onSkipReview={handleSkipReview} isGenerating={isGenerating} diff --git a/frontend/src/components/ScriptReviewSection.tsx b/frontend/src/components/ScriptReviewSection.tsx index 2cffc46..b8840a6 100644 --- a/frontend/src/components/ScriptReviewSection.tsx +++ b/frontend/src/components/ScriptReviewSection.tsx @@ -4,6 +4,9 @@ interface ScriptReviewSectionProps { segments: ScriptSegment[]; roles: Role[]; onSegmentChange: (segmentId: string, newSpeaker: string) => void; + onSegmentTextChange: (segmentId: string, newText: string) => void; + onSegmentSplit: (segmentId: string, splitPosition: number) => void; + onSegmentDelete: (segmentId: string) => void; onGenerate: () => void; onSkipReview: () => void; isGenerating: boolean; @@ -13,6 +16,9 @@ export default function ScriptReviewSection({ segments, roles, onSegmentChange, + onSegmentTextChange, + onSegmentSplit, + onSegmentDelete, onGenerate, onSkipReview, isGenerating, @@ -21,6 +27,26 @@ export default function ScriptReviewSection({ onSegmentChange(segmentId, newSpeaker); }; + const handleTextChange = (segmentId: string, newText: string) => { + onSegmentTextChange(segmentId, newText); + }; + + const handleSplit = (segmentId: string, text: string) => { + // Find a good split point (after a sentence or quote) + const quoteMatch = text.match(/^(.*?[.!?]"?\s*)(.*)/s); + if (quoteMatch && quoteMatch[1].length > 0 && quoteMatch[2].length > 0) { + onSegmentSplit(segmentId, quoteMatch[1].length); + return; + } + + // Fall back to middle split + const midPoint = Math.floor(text.length / 2); + const splitPoint = text.lastIndexOf(' ', midPoint); + if (splitPoint > 0) { + onSegmentSplit(segmentId, splitPoint + 1); + } + }; + return (