From 1fdcf99ded6a9eebd8ba26fd1f79ff64d4ab1eae Mon Sep 17 00:00:00 2001 From: Benjamin Bolte Date: Sat, 3 Aug 2024 08:20:06 -0400 Subject: [PATCH] finally implement image and urdf uploading --- .../components/listing/ListingArtifacts.tsx | 65 +++++++++++++++---- .../src/components/listing/ListingBody.tsx | 2 +- 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/listing/ListingArtifacts.tsx b/frontend/src/components/listing/ListingArtifacts.tsx index 062ca98a..e4f1301a 100644 --- a/frontend/src/components/listing/ListingArtifacts.tsx +++ b/frontend/src/components/listing/ListingArtifacts.tsx @@ -1,21 +1,30 @@ import Carousel from "components/ui/Carousel"; +import { FileSvgDraw } from "components/ui/FileSvgDraw"; +import { + FileUploader, + FileUploaderContent, + FileUploaderItem, +} from "components/ui/FileUpload"; import { components } from "gen/api"; import { useAlertQueue } from "hooks/useAlertQueue"; import { useAuthentication } from "hooks/useAuth"; +import { FileInput, Paperclip } from "lucide-react"; import { useEffect, useState } from "react"; interface Props { - listing_id: string; + listingId: string; // TODO: If can edit, allow the user to add and delete artifacts. edit: boolean; } const ListingArtifacts = (props: Props) => { - const { listing_id } = props; + const { listingId, edit } = props; const auth = useAuthentication(); const { addErrorAlert } = useAlertQueue(); + const [files, setFiles] = useState(null); + const [artifacts, setArtifacts] = useState< components["schemas"]["ListArtifactsResponse"] | null >(null); @@ -24,7 +33,7 @@ const ListingArtifacts = (props: Props) => { const fetchArtifacts = async () => { const { data, error } = await auth.client.GET("/artifacts/{listing_id}", { params: { - path: { listing_id }, + path: { listing_id: listingId }, }, }); @@ -35,18 +44,50 @@ const ListingArtifacts = (props: Props) => { } }; fetchArtifacts(); - }, [listing_id]); + }, [listingId]); if (artifacts != null && artifacts.artifacts.length > 0) { return ( - { - return { - url: artifact.url, - caption: artifact.name, - }; - })} - /> + <> + { + return { + url: artifact.url, + caption: artifact.name, + }; + })} + /> + {edit ?? ( +
+ + +
+ +
+
+ + {files && + files.length > 0 && + files.map((file, index: number) => ( + + + {file.name} + + ))} + +
+
+ )} + ); } else { return <>; diff --git a/frontend/src/components/listing/ListingBody.tsx b/frontend/src/components/listing/ListingBody.tsx index 9b90698b..e86f5c5a 100644 --- a/frontend/src/components/listing/ListingBody.tsx +++ b/frontend/src/components/listing/ListingBody.tsx @@ -23,7 +23,7 @@ const ListingBody = (props: ListingBodyProps) => { child_ids={listing.child_ids} edit={listing.owner_is_user} /> - + ); };