({
videoId,
transcript,
topics,
videoInfo,
user,
hasSpeakerData,
subscriptionStatus,
isCheckingSubscription,
fetchSubscriptionStatus,
onAuthRequired,
onBulkTranslation,
translationCache,
}: UseTranscriptExportOptions)
| 23 | } |
| 24 | |
| 25 | export function useTranscriptExport({ |
| 26 | videoId, |
| 27 | transcript, |
| 28 | topics, |
| 29 | videoInfo, |
| 30 | user, |
| 31 | hasSpeakerData, |
| 32 | subscriptionStatus, |
| 33 | isCheckingSubscription, |
| 34 | fetchSubscriptionStatus, |
| 35 | onAuthRequired, |
| 36 | onBulkTranslation, |
| 37 | translationCache, |
| 38 | }: UseTranscriptExportOptions) { |
| 39 | const router = useRouter(); |
| 40 | |
| 41 | const [isExportDialogOpen, setIsExportDialogOpen] = useState(false); |
| 42 | const [exportFormat, setExportFormat] = useState<TranscriptExportFormat>('txt'); |
| 43 | const [exportMode, setExportMode] = useState<TranscriptExportMode>('original'); |
| 44 | const [targetLanguage, setTargetLanguage] = useState<string>('es'); // Default to Spanish |
| 45 | const [includeTimestamps, setIncludeTimestamps] = useState(true); |
| 46 | const [includeSpeakers, setIncludeSpeakers] = useState(false); |
| 47 | const [exportErrorMessage, setExportErrorMessage] = useState<string | null>(null); |
| 48 | const [exportDisableMessage, setExportDisableMessage] = useState<string | null>(null); |
| 49 | const [isExportingTranscript, setIsExportingTranscript] = useState(false); |
| 50 | const [showExportUpsell, setShowExportUpsell] = useState(false); |
| 51 | const [translationProgress, setTranslationProgress] = useState<{ |
| 52 | completed: number; |
| 53 | total: number; |
| 54 | } | null>(null); |
| 55 | |
| 56 | useEffect(() => { |
| 57 | if (exportFormat === 'srt' && !includeTimestamps) { |
| 58 | setIncludeTimestamps(true); |
| 59 | } |
| 60 | }, [exportFormat, includeTimestamps]); |
| 61 | |
| 62 | useEffect(() => { |
| 63 | if (!hasSpeakerData && includeSpeakers) { |
| 64 | setIncludeSpeakers(false); |
| 65 | } |
| 66 | }, [hasSpeakerData, includeSpeakers]); |
| 67 | |
| 68 | const handleExportDialogOpenChange = useCallback((open: boolean) => { |
| 69 | setIsExportDialogOpen(open); |
| 70 | if (!open) { |
| 71 | setExportErrorMessage(null); |
| 72 | setExportDisableMessage(null); |
| 73 | // Reset non-essential state |
| 74 | setExportMode('original'); |
| 75 | } |
| 76 | }, []); |
| 77 | |
| 78 | const handleRequestExport = useCallback(async () => { |
| 79 | if (!videoId || transcript.length === 0) { |
| 80 | toast.error('Transcript is still loading. Try again in a few seconds.'); |
| 81 | return; |
| 82 | } |
no test coverage detected