import React from "react"; import {downloadArchiveMember, getArchiveContents} from "../api"; import {fileSuffixIconName, humanFileSize} from "./Common"; import {Icon, Message, Modal, Panel, Placeholder, Table} from "./ui"; function ArchiveEntry({entry, depth, archivePath}) { const [expanded, setExpanded] = React.useState(depth === 0); const indent = '\xa0\xa0\xa0\xa0'.repeat(depth); if (entry.is_dir) { const folderRows = expanded && entry.children ? entry.children.map((child, i) => ) : null; return setExpanded(!expanded)} style={{cursor: 'pointer'}}> {indent} {' '}{entry.name}/ — {folderRows} } const handleDownload = () => { downloadArchiveMember(archivePath, entry.path); }; return {indent} {' '}{entry.name} {' '} {humanFileSize(entry.size)} } function SkeletonRows() { return {[1, 2, 3].map(i => )} } export function ArchivePreviewContent({previewFile}) { const [contents, setContents] = React.useState(null); const [loading, setLoading] = React.useState(true); const [error, setError] = React.useState(null); const path = previewFile['primary_path'] || previewFile['path']; React.useEffect(() => { const fetchContents = async () => { setLoading(true); setError(null); try { const result = await getArchiveContents(path); if (result) { setContents(result); } else { setError('Could not read archive contents.'); } } catch (e) { setError(e.message || 'Could not read archive contents.'); } finally { setLoading(false); } }; fetchContents(); }, [path]); if (error) { return

{error}

} return {!loading && contents && {' '} {contents.total_files} files,{' '} {humanFileSize(contents.total_size)} total } Name Size {loading ? : contents && contents.entries.map((entry, i) => ) }
}