From f68157b290b222d14538fdb19dfb7b721ad4a58a Mon Sep 17 00:00:00 2001 From: Ben Bolte Date: Fri, 2 Aug 2024 12:05:03 -0700 Subject: [PATCH] better listing editing flow (#234) * better listing editing flow * linting * delete more * fix tests * last ui tweak --- frontend/package-lock.json | 45 ----- .../src/components/listing/AddOrEditList.tsx | 158 --------------- .../components/listing/EditListingModal.tsx | 180 ++++++++++++++++++ frontend/src/components/listing/List.tsx | 96 ---------- .../src/components/listing/ListingBody.tsx | 1 + .../listing/ListingDeleteButton.tsx | 4 +- .../components/listing/ListingDescription.tsx | 89 ++++++++- .../src/components/listing/ListingFooter.tsx | 21 +- .../src/components/listing/ListingHeader.tsx | 85 ++++++++- .../src/components/listings/ListingGrid.tsx | 2 +- .../components/listings/ListingGridCard.tsx | 63 +++--- frontend/src/components/ui/Button/Button.tsx | 2 + frontend/src/hooks/useGetListing.tsx | 1 + frontend/src/pages/Browse.tsx | 64 +------ frontend/src/pages/ListingDetails.tsx | 8 +- store/requirements.txt | 1 + 16 files changed, 415 insertions(+), 405 deletions(-) delete mode 100644 frontend/src/components/listing/AddOrEditList.tsx create mode 100644 frontend/src/components/listing/EditListingModal.tsx delete mode 100644 frontend/src/components/listing/List.tsx diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 698967ef..52c7b07c 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -4439,17 +4439,6 @@ "node": ">= 8" } }, - "node_modules/@popperjs/core": { - "version": "2.11.8", - "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz", - "integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==", - "dev": true, - "license": "MIT", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/popperjs" - } - }, "node_modules/@radix-ui/number": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@radix-ui/number/-/number-1.1.0.tgz", @@ -5732,22 +5721,6 @@ "resolved": "https://registry.npmjs.org/@radix-ui/rect/-/rect-1.1.0.tgz", "integrity": "sha512-A9+lCBZoaMJlVKcRBz2YByCG+Cp2t6nAnMnNba+XiWxnj6r4JUFqfsgwocMBZU9LPtdxC6wB56ySYpc7LQIoJg==" }, - "node_modules/@react-aria/ssr": { - "version": "3.9.5", - "resolved": "https://registry.npmjs.org/@react-aria/ssr/-/ssr-3.9.5.tgz", - "integrity": "sha512-xEwGKoysu+oXulibNUSkXf8itW0npHHTa6c4AyYeZIJyRoegeteYuFpZUBPtIDE8RfHdNsSmE1ssOkxRnwbkuQ==", - "dev": true, - "license": "Apache-2.0", - "dependencies": { - "@swc/helpers": "^0.5.0" - }, - "engines": { - "node": ">= 12" - }, - "peerDependencies": { - "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0" - } - }, "node_modules/@react-native-community/cli": { "version": "13.6.9", "resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-13.6.9.tgz", @@ -16115,7 +16088,6 @@ "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", "integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==", "license": "MIT", - "peer": true, "dependencies": { "loose-envify": "^1.0.0" } @@ -27500,23 +27472,6 @@ } } }, - "node_modules/react-transition-group": { - "version": "4.4.5", - "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.5.tgz", - "integrity": "sha512-pZcd1MCJoiKiBR2NRxeCRg13uCXbydPnmB4EOeRrY7480qNWO8IIgQG6zlDkm6uRMsURXPuKq0GWtiM59a5Q6g==", - "dev": true, - "license": "BSD-3-Clause", - "dependencies": { - "@babel/runtime": "^7.5.5", - "dom-helpers": "^5.0.1", - "loose-envify": "^1.4.0", - "prop-types": "^15.6.2" - }, - "peerDependencies": { - "react": ">=16.6.0", - "react-dom": ">=16.6.0" - } - }, "node_modules/react-use-measure": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/react-use-measure/-/react-use-measure-2.1.1.tgz", diff --git a/frontend/src/components/listing/AddOrEditList.tsx b/frontend/src/components/listing/AddOrEditList.tsx deleted file mode 100644 index d5062a87..00000000 --- a/frontend/src/components/listing/AddOrEditList.tsx +++ /dev/null @@ -1,158 +0,0 @@ -import { zodResolver } from "@hookform/resolvers/zod"; -import RequireAuthentication from "components/auth/RequireAuthentication"; -import { Button } from "components/ui/Button/Button"; -import { - Dialog, - DialogContent, - DialogFooter, - DialogHeader, - DialogTitle, -} from "components/ui/dialog"; -import ErrorMessage from "components/ui/ErrorMessage"; -import { FileSvgDraw } from "components/ui/FileSvgDraw"; -import { Input, TextArea } from "components/ui/Input/Input"; -import { useAlertQueue } from "hooks/alerts"; -import { useAuthentication } from "hooks/auth"; -import useGetListing from "hooks/useGetListing"; -import { Paperclip } from "lucide-react"; -import { useState } from "react"; -import { SubmitHandler, useForm } from "react-hook-form"; -import { FormType, NewListingSchema, NewListingType } from "types"; -import { - FileInput, - FileUploader, - FileUploaderContent, - FileUploaderItem, -} from "../ui/FileUpload"; - -const dropZoneConfig = { - maxFiles: 5, - maxSize: 1024 * 1024 * 4, - multiple: true, -}; - -interface AddOrEditProps { - open: boolean; - listId: string; - onClose: (open: boolean) => void; - formType: FormType; -} -const AddOrEditList = ({ open, onClose, listId, formType }: AddOrEditProps) => { - const [files, setFiles] = useState(null); - const { addAlert, addErrorAlert } = useAlertQueue(); - const auth = useAuthentication(); - const { listing } = useGetListing(listId); - const { - register, - handleSubmit, - setValue, - formState: { errors }, - } = useForm({ - resolver: zodResolver(NewListingSchema), - }); - - if (listing && formType === "edit") { - setValue("name", listing?.name); - setValue("description", listing?.description ?? ""); - } - - const onSubmit: SubmitHandler = async ({ - name, - description, - }: NewListingType) => { - // TODO: change http according to formType and add files (imgs/urdf) to artifact - const { error } = await auth.client.POST("/listings/add", { - body: { - name, - description, - child_ids: [], - }, - }); - - if (error) { - addErrorAlert(error); - } else { - addAlert("Listing added successfully", "success"); - onClose(false); - window.location.reload(); - } - }; - - return ( - -
- - - - - Add Robo Details - - -
-
- - {errors?.name && ( - {errors?.name?.message} - )} -
-
-