From 71180cbac42a1eb20b85d360a6371a7838364d5b Mon Sep 17 00:00:00 2001 From: nikec Date: Sat, 2 Dec 2023 00:19:46 +0100 Subject: [PATCH] demo --- .../Explorer/CopyProgress/index.tsx | 130 ++++++++++++++++++ interface/app/$libraryId/Explorer/index.tsx | 5 + packages/ui/src/ProgressBar.tsx | 4 +- 3 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 interface/app/$libraryId/Explorer/CopyProgress/index.tsx diff --git a/interface/app/$libraryId/Explorer/CopyProgress/index.tsx b/interface/app/$libraryId/Explorer/CopyProgress/index.tsx new file mode 100644 index 000000000..7ffc8d969 --- /dev/null +++ b/interface/app/$libraryId/Explorer/CopyProgress/index.tsx @@ -0,0 +1,130 @@ +import { X } from '@phosphor-icons/react'; +import { Grid, useGrid } from '@virtual-grid/react'; +import { memo, useEffect, useRef, useState } from 'react'; +import { byteSize, ExplorerItem, getExplorerItemData, getItemFilePath } from '@sd/client'; +import { Button, ProgressBar } from '@sd/ui'; + +import { useExplorerContext } from '../Context'; +import { FileThumb } from '../FilePath/Thumb'; + +type Item = { item: ExplorerItem; size: number; progress: number }; + +export const CopyProgress = () => { + const explorer = useExplorerContext(); + + const [[items], setItems] = useState<[Map]>([new Map()]); + + const scrollRef = useRef(null); + + const grid = useGrid({ scrollRef, count: items.size, size: { height: 80 } }); + + useEffect(() => { + if (items.size !== 0 || !explorer.items || explorer.items.length === 0) return; + setItems([ + new Map( + explorer.items.slice(0, 10).map((item, i) => { + const filePath = getItemFilePath(item); + const size = filePath?.size_in_bytes_bytes; + return [ + i, + { + item, + size: size + ? Number(byteSize(size).original) + : Math.floor(Math.random() * 1000000), + progress: 0 + } + ]; + }) + ) + ]); + }, [explorer.items, items.size]); + + useEffect(() => { + const interval = setInterval(() => { + let finished = 0; + let change = false; + + const updated = [...items].map(([i, item]) => { + let progress = item.progress; + + if (progress === item.size) { + finished++; + return [i, item] as const; + } + + if (Math.random() < 0.5) { + let difference = item.size - item.progress; + if (item.progress <= item.size / 2) difference = difference / 2; + progress += Math.floor(Math.random() * difference) + 1; + change = true; + } + + if (progress === item.size) finished++; + return [i, { ...item, progress }] as const; + }); + + if (finished === items.size) clearInterval(interval); + if (change) setItems([new Map(updated)]); + }, 750); + + return () => clearInterval(interval); + }, [items]); + + return ( +
+
+

Copying

+ +
+ +
+ + {(index) => { + const item = items.get(index); + if (!item) return null; + + return ( +
+ +
+ + {getExplorerItemData(item.item).fullName} + + + {`${byteSize(item.progress)}`} / {`${byteSize(item.size)}`} + {item.progress === 0 + ? ' - Waiting' + : item.progress < item.size + ? ' - Copying' + : ' - Done'} + + +
+
+ ); + }} +
+
+
+ ); +}; + +const Thumb = memo(({ item }: { item: ExplorerItem }) => { + return ( + + ); +}); diff --git a/interface/app/$libraryId/Explorer/index.tsx b/interface/app/$libraryId/Explorer/index.tsx index 93c692649..2764e0b02 100644 --- a/interface/app/$libraryId/Explorer/index.tsx +++ b/interface/app/$libraryId/Explorer/index.tsx @@ -17,6 +17,8 @@ import { ExplorerPath, PATH_BAR_HEIGHT } from './View/ExplorerPath'; import 'react-slidedown/lib/slidedown.css'; +import { CopyProgress } from './CopyProgress'; + interface Props { emptyNotice?: ExplorerViewProps['emptyNotice']; contextMenu?: () => ReactNode; @@ -102,8 +104,11 @@ export default function Explorer(props: PropsWithChildren) { + {showPathBar && } + + {explorerStore.showInspector && ( { if (props.pending) { return ( -
+
); @@ -33,7 +33,7 @@ export const ProgressBar = memo((props: ProgressBarProps) => { return (