import { useState } from 'react'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { useAppStore } from '@/stores/app-store'; import { ipc } from '@/lib/ipc'; import { toast } from '@/lib/toast'; import { ExportDialogFooter } from './ExportDialogFooter'; const extFor = (format: 'pdf' | 'docx' | 'html' | 'png') => format === 'pdf' ? '.pdf' : format === 'docx' ? '.docx' : format === 'png' ? '.png' : '.html'; export function ExportBatchDialog({ sourcePaths }: { sourcePaths: string[] }) { const closeModal = useAppStore((s) => s.closeModal); const [format, setFormat] = useState<'pdf' | 'docx' | 'html' | 'png'>('pdf'); const [concurrency, setConcurrency] = useState(4); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(null); const handleSubmit = async () => { setSubmitting(true); setError(null); const items = sourcePaths.map((p) => ({ inputPath: p, outputPath: p.replace(/\.md$/, extFor(format)), })); const result = await ipc.export.batch(items, { format, concurrency }); if (!result.ok) { toast.error(`Export failed: ${result.error.message}`); setError(result.error.message); setSubmitting(false); } else { toast.success(`Exported ${sourcePaths.length} files`); closeModal(); } }; return ( !o && closeModal()}> Batch export {sourcePaths.length} files
{sourcePaths.map((p) =>
{p}
)}
{error && (
{error}
)}
); }