From 1d5d92f678f15d82352993f3d6e09d922e56dff4 Mon Sep 17 00:00:00 2001 From: DaneEveritt Date: Sun, 24 Jul 2022 18:03:45 -0400 Subject: [PATCH] Use a different styling for file uploads --- .../server/files/FileManagerContainer.tsx | 2 +- .../server/files/FileManagerStatus.tsx | 140 ++++++++++-------- 2 files changed, 80 insertions(+), 62 deletions(-) diff --git a/resources/scripts/components/server/files/FileManagerContainer.tsx b/resources/scripts/components/server/files/FileManagerContainer.tsx index 83440aecc..3bebd2062 100644 --- a/resources/scripts/components/server/files/FileManagerContainer.tsx +++ b/resources/scripts/components/server/files/FileManagerContainer.tsx @@ -75,6 +75,7 @@ export default () => { />
+ @@ -105,7 +106,6 @@ export default () => { ))} -
)} diff --git a/resources/scripts/components/server/files/FileManagerStatus.tsx b/resources/scripts/components/server/files/FileManagerStatus.tsx index a286c4155..2e4144d0f 100644 --- a/resources/scripts/components/server/files/FileManagerStatus.tsx +++ b/resources/scripts/components/server/files/FileManagerStatus.tsx @@ -1,72 +1,90 @@ -import React from 'react'; -import tw, { styled } from 'twin.macro'; +import React, { useContext, useEffect, useState } from 'react'; import { ServerContext } from '@/state/server'; -import { bytesToString } from '@/lib/formatters'; +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 SpinnerCircle = styled.circle` - transition: stroke-dashoffset 0.35s; - transform: rotate(-90deg); - transform-origin: 50% 50%; -`; +const svgProps = { + cx: 16, + cy: 16, + r: 14, + strokeWidth: 3, + fill: 'none', + stroke: 'currentColor', +}; -function Spinner({ progress }: { progress: number }) { - const stroke = 3; - const radius = 20; - const normalizedRadius = radius - stroke * 2; - const circumference = normalizedRadius * 2 * Math.PI; +const Spinner = ({ progress, className }: { progress: number; className?: string }) => ( + + + + +); - return ( - - - - +const FileUploadList = () => { + const { close } = useContext(DialogWrapperContext); + const uploads = ServerContext.useStoreState((state) => + state.files.uploads.sort((a, b) => a.name.localeCompare(b.name)) ); -} - -function FileManagerStatus() { - const uploads = ServerContext.useStoreState((state) => state.files.uploads); return ( -
- {uploads.length > 0 && ( -
- {uploads - .sort((a, b) => a.total - b.total) - .map((f) => ( -
-
- -
- -
- - {f.name} ({bytesToString(f.loaded)}/{bytesToString(f.total)}) - -
-
- ))} +
+ {uploads.map((file) => ( +
+ +
+ +
+
+ {file.name}
- )} + ))} + + Close +
); -} +}; -export default FileManagerStatus; +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 && ( + + + + )} + + + ); +};