Merge pull request #57 from RobbyV2/feat/MultiUpload

This commit is contained in:
Richard Roberson 2025-07-19 21:16:29 -06:00 committed by GitHub
commit ba461b20c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -41,24 +41,27 @@ export function DocumentUploader({ className = '' }: DocumentUploaderProps) {
}; };
const onDrop = useCallback(async (acceptedFiles: File[]) => { const onDrop = useCallback(async (acceptedFiles: File[]) => {
const file = acceptedFiles[0]; if (!acceptedFiles || acceptedFiles.length === 0) return;
if (!file) return;
setIsUploading(true); setIsUploading(true);
setError(null); setError(null);
try { try {
if (file.type === 'application/pdf') { for (const file of acceptedFiles) {
await addPDF(file); if (file.type === 'application/pdf') {
} else if (file.type === 'application/epub+zip') { await addPDF(file);
await addEPUB(file); } else if (file.type === 'application/epub+zip') {
} else if (file.type === 'text/plain' || file.type === 'text/markdown' || file.name.endsWith('.md')) { await addEPUB(file);
await addHTML(file); } else if (file.type === 'text/plain' || file.type === 'text/markdown' || file.name.endsWith('.md')) {
} else if (isDev && file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') { await addHTML(file);
setIsUploading(false); } else if (isDev && file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') {
setIsConverting(true); setIsUploading(false);
const pdfFile = await convertDocxToPdf(file); setIsConverting(true);
await addPDF(pdfFile); const pdfFile = await convertDocxToPdf(file);
await addPDF(pdfFile);
setIsConverting(false);
setIsUploading(true);
}
} }
} catch (err) { } catch (err) {
setError('Failed to upload file. Please try again.'); setError('Failed to upload file. Please try again.');
@ -80,7 +83,7 @@ export function DocumentUploader({ className = '' }: DocumentUploaderProps) {
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': ['.docx'] 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': ['.docx']
} : {}) } : {})
}, },
multiple: false, multiple: true,
disabled: isUploading || isConverting disabled: isUploading || isConverting
}); });
@ -110,7 +113,7 @@ export function DocumentUploader({ className = '' }: DocumentUploaderProps) {
) : ( ) : (
<> <>
<p className="mb-2 text-sm sm:text-lg font-semibold text-foreground"> <p className="mb-2 text-sm sm:text-lg font-semibold text-foreground">
{isDragActive ? 'Drop your file here' : 'Drop your file here, or click to select'} {isDragActive ? 'Drop your file(s) here' : 'Drop your file(s) here, or click to select'}
</p> </p>
<p className="text-xs sm:text-sm text-muted"> <p className="text-xs sm:text-sm text-muted">
{isDev ? 'PDF, EPUB, TXT, MD, or DOCX files are accepted' : 'PDF, EPUB, TXT, or MD files are accepted'} {isDev ? 'PDF, EPUB, TXT, MD, or DOCX files are accepted' : 'PDF, EPUB, TXT, or MD files are accepted'}