From 1fdcf99ded6a9eebd8ba26fd1f79ff64d4ab1eae Mon Sep 17 00:00:00 2001 From: Benjamin Bolte Date: Sat, 3 Aug 2024 08:20:06 -0400 Subject: [PATCH 1/4] 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} /> - + ); }; From beca0d9cf8b87ca3dc33694d27894edf78027dab Mon Sep 17 00:00:00 2001 From: Benjamin Bolte Date: Sun, 4 Aug 2024 15:11:05 -0400 Subject: [PATCH 2/4] more wip --- .../components/listing/EditListingModal.tsx | 80 +++++++++---------- .../components/{ui => listing}/FileUpload.tsx | 4 +- .../components/listing/ListingArtifacts.tsx | 72 ++++++----------- frontend/src/components/ui/FileSvgDraw.tsx | 28 ------- 4 files changed, 68 insertions(+), 116 deletions(-) rename frontend/src/components/{ui => listing}/FileUpload.tsx (98%) delete mode 100644 frontend/src/components/ui/FileSvgDraw.tsx diff --git a/frontend/src/components/listing/EditListingModal.tsx b/frontend/src/components/listing/EditListingModal.tsx index 72bbd013..1f5000b5 100644 --- a/frontend/src/components/listing/EditListingModal.tsx +++ b/frontend/src/components/listing/EditListingModal.tsx @@ -1,5 +1,10 @@ import { zodResolver } from "@hookform/resolvers/zod"; import RequireAuthentication from "components/auth/RequireAuthentication"; +import { + FileUploader, + FileUploaderContent, + FileUploaderItem, +} from "components/listing/FileUpload"; import { Button } from "components/ui/Button/Button"; import { Dialog, @@ -13,16 +18,12 @@ import { Input, TextArea } from "components/ui/Input/Input"; import { paths } from "gen/api"; import { useAlertQueue } from "hooks/useAlertQueue"; import { useAuthentication } from "hooks/useAuth"; +import { FileInput, Paperclip } from "lucide-react"; import { useEffect, useState } from "react"; import { SubmitHandler, useForm } from "react-hook-form"; +import { FaFileUpload } from "react-icons/fa"; import { NewListingSchema, NewListingType } from "types"; -// const dropZoneConfig = { -// maxFiles: 5, -// maxSize: 1024 * 1024 * 4, -// multiple: true, -// }; - interface AddOrEditProps { open: boolean; listingId: string; @@ -33,7 +34,7 @@ type ListingResponse = paths["/listings/{id}"]["get"]["responses"][200]["content"]["application/json"]; const EditListingModal = ({ open, onClose, listingId }: AddOrEditProps) => { - // const [files, setFiles] = useState(null); + const [files, setFiles] = useState(null); const { addAlert, addErrorAlert } = useAlertQueue(); const auth = useAuthentication(); const [listing, setListing] = useState(null); @@ -98,9 +99,9 @@ const EditListingModal = ({ open, onClose, listingId }: AddOrEditProps) => { return ( - + - + Add Robo Details @@ -114,7 +115,6 @@ const EditListingModal = ({ open, onClose, listingId }: AddOrEditProps) => { placeholder="Name" type="text" {...register("name")} - className="text-white" disabled={listing === null} /> {errors?.name && ( @@ -127,7 +127,7 @@ const EditListingModal = ({ open, onClose, listingId }: AddOrEditProps) => {