import React, { useContext, useEffect, useState } from 'react'; import { ServerContext } from '@/state/server'; import { CloudUploadIcon } from '@heroicons/react/solid'; import asDialog from '@/hoc/asDialog'; import { Dialog, DialogWrapperContext } from '@/components/elements/dialog'; import { Button } from '@/components/elements/button/index'; import Tooltip from '@/components/elements/tooltip/Tooltip'; import Code from '@/components/elements/Code'; const svgProps = { cx: 16, cy: 16, r: 14, strokeWidth: 3, fill: 'none', stroke: 'currentColor', }; const Spinner = ({ progress, className }: { progress: number; className?: string }) => ( ); const FileUploadList = () => { const { close } = useContext(DialogWrapperContext); const uploads = ServerContext.useStoreState((state) => state.files.uploads.sort((a, b) => a.name.localeCompare(b.name)) ); return (
{uploads.map((file) => (
{file.name}
))} Close
); }; const FileUploadListDialog = asDialog({ title: 'File Uploads', description: 'The following files are being uploaded to your server.', })(FileUploadList); export default () => { const [open, setOpen] = useState(false); const count = ServerContext.useStoreState((state) => state.files.uploads.length); const progress = ServerContext.useStoreState((state) => ({ uploaded: state.files.uploads.reduce((count, file) => count + file.loaded, 0), total: state.files.uploads.reduce((count, file) => count + file.total, 0), })); useEffect(() => { if (count === 0) { setOpen(false); } }, [count]); return ( <> {count > 0 && ( )} ); };