import React, { useContext, useEffect } from 'react'; import { ServerContext } from '@/state/server'; import { CloudUploadIcon, XIcon } 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'; import { useSignal } from '@preact/signals-react'; 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 removeFileUpload = ServerContext.useStoreActions((actions) => actions.files.removeFileUpload); const clearFileUploads = ServerContext.useStoreActions((actions) => actions.files.clearFileUploads); const uploads = ServerContext.useStoreState((state) => Object.entries(state.files.uploads).sort(([a], [b]) => a.localeCompare(b)) ); return (
{uploads.map(([name, file]) => (
{name}
))} clearFileUploads()}> Cancel Uploads Close
); }; const FileUploadListDialog = asDialog({ title: 'File Uploads', description: 'The following files are being uploaded to your server.', })(FileUploadList); export default () => { const open = useSignal(false); const count = ServerContext.useStoreState((state) => Object.keys(state.files.uploads).length); const progress = ServerContext.useStoreState((state) => ({ uploaded: Object.values(state.files.uploads).reduce((count, file) => count + file.loaded, 0), total: Object.values(state.files.uploads).reduce((count, file) => count + file.total, 0), })); useEffect(() => { if (count === 0) { open.value = false; } }, [count]); return ( <> {count > 0 && ( )} (open.value = false)} /> ); };