From 11249f3befeade8131138ae00ec06553e0f766da Mon Sep 17 00:00:00 2001 From: florian <> Date: Wed, 27 Mar 2024 22:31:29 +0100 Subject: [PATCH] feat: added gallery view --- src/components/BlobList/BlobList.css | 20 ++++ src/components/BlobList/BlobList.tsx | 131 ++++++++++++++++++----- src/components/ServerList/ServerList.tsx | 2 +- src/pages/Home.tsx | 24 ++--- 4 files changed, 139 insertions(+), 38 deletions(-) diff --git a/src/components/BlobList/BlobList.css b/src/components/BlobList/BlobList.css index ba45abd..eeacb2e 100644 --- a/src/components/BlobList/BlobList.css +++ b/src/components/BlobList/BlobList.css @@ -22,3 +22,23 @@ .blob-list .blob a { @apply cursor-pointer; } + +.blog-list-header { + @apply flex flex-row mt-4; +} + +.blog-list-header h2 { + @apply flex-grow; +} + +.blog-list-header button { + @apply bg-neutral-800 hover:bg-neutral-700 p-2 ml-2 rounded-lg; +} + +.blog-list-header button.selected { + @apply bg-pink-700 text-white; +} + +.blog-list-header svg { + @apply w-6 text-white opacity-80 hover:opacity-100; +} diff --git a/src/components/BlobList/BlobList.tsx b/src/components/BlobList/BlobList.tsx index 2384b3c..2dd4431 100644 --- a/src/components/BlobList/BlobList.tsx +++ b/src/components/BlobList/BlobList.tsx @@ -1,39 +1,122 @@ -import { DocumentIcon, TrashIcon } from '@heroicons/react/24/outline'; +import { DocumentIcon, ListBulletIcon, PhotoIcon, TrashIcon } from '@heroicons/react/24/outline'; import { BlobDescriptor } from 'blossom-client-sdk'; import { formatDate, formatFileSize } from '../../utils'; import './BlobList.css'; +import { useState } from 'react'; + +type ListMode = 'gallery' | 'list'; type BlobListProps = { blobs: BlobDescriptor[]; onDelete?: (blob: BlobDescriptor) => void; + title?: string; }; -const BlobList = ({ blobs, onDelete }: BlobListProps) => { + +const BlobList = ({ blobs, onDelete, title }: BlobListProps) => { + const [mode, setMode] = useState('list'); + return ( -
- {blobs.map((blob: BlobDescriptor) => ( -
- - - - - - {blob.sha256} - - - {formatFileSize(blob.size)} - {blob.type && `${blob.type}`} - {formatDate(blob.created)} - {onDelete && ( + <> +
+ {title &&

{title}

} +
+ + +
+
+ + {mode == 'gallery' && ( +
+ {blobs + .filter(b => b.type?.startsWith('image/')) + .map(blob => ( +
+ +
+
+
+ {formatFileSize(blob.size)} + {formatDate(blob.created)} +
+
+ ))} +
+ )} + + {mode == 'list' && ( +
+ {blobs.map((blob: BlobDescriptor) => ( +
+ + + + + + {blob.sha256} + + + {formatFileSize(blob.size)} + {blob.type && `${blob.type}`} + {formatDate(blob.created)} + {onDelete && ( + + onDelete(blob)}> + + + + )} +
+ ))} +
+ )} + + ); + /* + )} + } else { + return ( +
+ {blobs.map((blob: BlobDescriptor) => ( +
- onDelete(blob)}> - + + + + + {blob.sha256} - )} -
- ))} -
- ); + {formatFileSize(blob.size)} + {blob.type && `${blob.type}`} + {formatDate(blob.created)} + {onDelete && ( + + onDelete(blob)}> + + + + )} +
+ ))} +
+ ); + }*/ }; export default BlobList; diff --git a/src/components/ServerList/ServerList.tsx b/src/components/ServerList/ServerList.tsx index 382ed93..755004a 100644 --- a/src/components/ServerList/ServerList.tsx +++ b/src/components/ServerList/ServerList.tsx @@ -12,7 +12,7 @@ type ServerListProps = { onCheck?: (server: string) => void; }; -export const ServerList = ({ servers, selectedServer, setSelectedServer, onTransfer, onCancel, onCheck }: ServerListProps) => { +export const ServerList = ({ servers, selectedServer, setSelectedServer, onTransfer, onCancel }: ServerListProps) => { const { serverInfo, distribution } = useServerInfo(); const blobsWithOnlyOneOccurance = Object.values(distribution) .filter(d => d.servers.length == 1) diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 36256b1..8a20e0b 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -68,19 +68,17 @@ function Home() { > {selectedServer && serverInfo[selectedServer] && selectedServerBlobs && ( - <> -

Your objects on {serverInfo[selectedServer].name}

- - deleteBlob.mutate({ - serverName: serverInfo[selectedServer].name, - serverUrl: serverInfo[selectedServer].url, - hash: blob.sha256, - }) - } - > - + + deleteBlob.mutate({ + serverName: serverInfo[selectedServer].name, + serverUrl: serverInfo[selectedServer].url, + hash: blob.sha256, + }) + } + > )} );