From ece049908ccf8def1efa70f25711167314450bce Mon Sep 17 00:00:00 2001 From: Utku Bakir <74243531+utkubakir@users.noreply.github.com> Date: Mon, 6 May 2024 20:34:44 -0400 Subject: [PATCH] spacedrop dialog pages --- .../$libraryId/Spacedrop/SpacedropDialog.tsx | 129 ++++++++++-------- 1 file changed, 74 insertions(+), 55 deletions(-) diff --git a/interface/app/$libraryId/Spacedrop/SpacedropDialog.tsx b/interface/app/$libraryId/Spacedrop/SpacedropDialog.tsx index 70a1c765f..e46a7b5b9 100644 --- a/interface/app/$libraryId/Spacedrop/SpacedropDialog.tsx +++ b/interface/app/$libraryId/Spacedrop/SpacedropDialog.tsx @@ -1,18 +1,11 @@ import { Cloud, Devices } from '@phosphor-icons/react/dist/ssr'; import * as RDialog from '@radix-ui/react-dialog'; import clsx from 'clsx'; -import { ReactNode, useState } from 'react'; -import { - ExplorerItem, - HardwareModel, - useBridgeMutation, - useDiscoveredPeers, - useZodForm -} from '@sd/client'; +import { useState } from 'react'; +import { ExplorerItem, useBridgeMutation, useDiscoveredPeers, useZodForm } from '@sd/client'; import { Button, Dialog, Divider, Tooltip, useDialog, UseDialogProps, z } from '@sd/ui'; import { Icon } from '~/components'; import { useLocale } from '~/hooks'; -import { hardwareModelToIcon } from '~/util/hardware'; import { usePlatform } from '~/util/Platform'; import { Image } from '../Explorer/FilePath/Image'; @@ -29,12 +22,13 @@ function getSpacedropItems(items: ExplorerItem[]) { // TODO: Handle multiple items, we wanna show user a list and let them select which items to spacedrop // TODO: Error handling for Spacedrop Cloud (e.g. file too big) +// TODO: Weird component structure, too many states, components and logic. Maybe refactor? export default function SpacedropDialog({ items, ...props }: SpacedropDialogProps) { const dialog = useDialog(props); const { t } = useLocale(); - const discoveredPeers = useDiscoveredPeers(); - const [destination, setDestination] = useState(); + // destination name (cloud or peer name) + const [destination, setDestination] = useState('cloud'); // dialog page state (0: pick items/p2p spacedrop, 1: cloud spacedrop config, 2: cloud spacedrop progress/url) const [page, setPage] = useState(0); @@ -48,7 +42,17 @@ export default function SpacedropDialog({ items, ...props }: SpacedropDialogProp const p2pSpacedrop = useBridgeMutation('p2p.spacedrop'); - const [spacedropItems, setSpacedropItems] = useState(getSpacedropItems(items)); + function handleSendFile() { + console.log('destination', destination); + if (destination === 'cloud') { + // handle cloud spacedrop + } else { + // handle p2p spacedrop + // p2pSpacedrop({ destination, items }); + } + // temp + dialog.close(); + } return ( @@ -64,38 +68,15 @@ export default function SpacedropDialog({ items, ...props }: SpacedropDialogProp {/* Content */} - {spacedropItems.length > 1 ? ( - - ) : spacedropItems.length === 1 ? ( -
-
-
- {Array.from(discoveredPeers).map(([id, meta]) => ( - } - name={meta.metadata.name} - isSelected={destination === meta.metadata.name} - onClick={() => setDestination(meta.metadata.name)} - /> - ))} - } - name="Spacedrive Cloud" - isSelected={destination === 'cloud'} - onClick={() => setDestination('cloud')} - /> -
-
- {spacedropItems.map((item, index) => ( - - ))} -
- ) : ( -
-

No items selected.

-
+ {page === 0 && ( + )} + {page === 1 && } + {page === 2 && } {/* Buttons */}
@@ -103,9 +84,13 @@ export default function SpacedropDialog({ items, ...props }: SpacedropDialogProp {t('cancel')} - {destination && ( - + ) : ( + )}
@@ -160,15 +145,49 @@ function BasicFileItem(props: { data: ExplorerItem }) { ); } -function Node(props: { id: string; name: string; model: HardwareModel }) { - return ( -
- - {props.name} +function SpacedropHome(props: { + items: ExplorerItem[]; + destination: string; + setDestination: (destination: string) => void; +}) { + const { destination, setDestination, items } = props; + + const { t } = useLocale(); + + const discoveredPeers = useDiscoveredPeers(); + + const [spacedropItems, setSpacedropItems] = useState(getSpacedropItems(items)); + + return spacedropItems.length > 1 ? ( + + ) : spacedropItems.length === 1 ? ( +
+
+
+ {Array.from(discoveredPeers).map(([id, meta]) => ( + } + name={meta.metadata.name} + isSelected={destination === meta.metadata.name} + onClick={() => setDestination(meta.metadata.name)} + /> + ))} + } + name={t('spacedrive_cloud')} + isSelected={destination === 'cloud'} + onClick={() => setDestination('cloud')} + /> +
+
+ {spacedropItems.map((item, index) => ( + + ))} +
+ ) : ( +
+

{t('nothing_selected')}

); }