import React, { useState, useEffect } from 'react'; import { useTranscriptionStore } from '../stores/transcriptionStore'; import LanguageSelector from './LanguageSelector'; import TranscriptionWarningModal from './TranscriptionWarningModal'; import { checkTranscriptionWarnings, getMediaDuration, WARNING_MESSAGES } from '../utils/transcriptionWarnings'; type WarningType = keyof typeof WARNING_MESSAGES; const TranscriptionControls: React.FC = () => { const { file, transcription, isLoading, isProcessingVideo, error, serverStatus, selectedLanguage, selectedScript, handleTranscribe, setSelectedLanguageAndScript, } = useTranscriptionStore(); const [showWarningModal, setShowWarningModal] = useState(false); const [warnings, setWarnings] = useState([]); const [mediaDuration, setMediaDuration] = useState(undefined); // Get media duration when file changes useEffect(() => { if (file) { getMediaDuration(file) .then(duration => { setMediaDuration(duration); }) .catch(error => { console.warn('Could not get media duration:', error); setMediaDuration(undefined); }); } else { setMediaDuration(undefined); } }, [file]); // Handle transcribe button click with warning check const handleTranscribeClick = async () => { if (!file) return; // Check for warnings const detectedWarnings = checkTranscriptionWarnings({ file, duration: mediaDuration, }); if (detectedWarnings.length > 0) { setWarnings(detectedWarnings); setShowWarningModal(true); } else { // No warnings, proceed directly await handleTranscribe(); } }; // Handle warning modal acceptance const handleWarningAccept = async () => { setShowWarningModal(false); await handleTranscribe(); }; // Handle warning modal cancellation const handleWarningCancel = () => { setShowWarningModal(false); setWarnings([]); }; // Only show controls if file exists but no transcription yet if (!file || transcription) { return null; } return ( <>
{/* Error Display */} {error && (
Error
{error}
)} {/* Controls Container */}
{/* Language Selection */}
{/* Transcribe Button */}
{/* Warning Modal */} ); }; export default TranscriptionControls;