import React, { useEffect, useState } from 'react'; import axios from 'axios'; import { FileText, Download, ArrowLeft, FolderOpen } from 'lucide-react'; import { motion } from 'framer-motion'; const FileViewer = ({ folderId, onBack }) => { const [files, setFiles] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const fetchFiles = async () => { try { const response = await axios.get(`http://localhost:8000/processed/${folderId}`); setFiles(response.data); } catch (error) { console.error("Failed to fetch files", error); } finally { setLoading(false); } }; if (folderId) fetchFiles(); }, [folderId]); const handleDownload = (path, filename) => { // Trigger download const link = document.createElement('a'); link.href = `http://localhost:8000/${path}`; link.setAttribute('download', filename); document.body.appendChild(link); link.click(); link.parentNode.removeChild(link); }; if (loading) { return
Loading files...
; } return (

{folderId}

{files.length === 0 ? (
No files found in this folder.
) : ( files.map((file) => (

{file.name}

{(file.size / 1024).toFixed(1)} KB

)) )}
); }; export default FileViewer;