From 685919f113910b7a812f96c761c31ecc45a77014 Mon Sep 17 00:00:00 2001 From: Dennis Chen <41879777+chennisden@users.noreply.github.com> Date: Mon, 17 Jun 2024 09:29:24 -0700 Subject: [PATCH] Upload images for parts too (#137) --- frontend/src/components/PartForm.tsx | 22 +++++++++++----------- frontend/src/pages/Parts.tsx | 19 +++++++++++++------ frontend/src/pages/YourParts.tsx | 19 +++++++++++++------ 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/frontend/src/components/PartForm.tsx b/frontend/src/components/PartForm.tsx index c3c78e5f..1e1fdbab 100644 --- a/frontend/src/components/PartForm.tsx +++ b/frontend/src/components/PartForm.tsx @@ -1,6 +1,7 @@ import { Image } from "hooks/api"; import { ChangeEvent, Dispatch, FormEvent, SetStateAction } from "react"; import { Button, Col, Form, Row } from "react-bootstrap"; +import ImageUploadComponent from "./files/UploadImage"; interface PartFormProps { title: string; @@ -44,6 +45,12 @@ const PartForm: React.FC = ({ setImages(newImages); }; + const handleImageUploadSuccess = (url: string, index: number) => { + const newImages = [...part_images]; + newImages[index].url = url; + setImages(newImages); + }; + return ( <>

{title}

@@ -75,15 +82,8 @@ const PartForm: React.FC = ({ {part_images.map((image, index) => ( - - handleImageChange(index, e)} - required + handleImageUploadSuccess(url, index)} /> = ({ diff --git a/frontend/src/pages/Parts.tsx b/frontend/src/pages/Parts.tsx index 8145808c..be12b4cb 100644 --- a/frontend/src/pages/Parts.tsx +++ b/frontend/src/pages/Parts.tsx @@ -1,3 +1,4 @@ +import ImageComponent from "components/files/ViewImage"; import { useAlertQueue } from "hooks/alerts"; import { api, Part } from "hooks/api"; import { useAuthentication } from "hooks/auth"; @@ -92,12 +93,18 @@ const Parts = () => { {partsData.map((part) => ( navigate(`/part/${part.part_id}`)}> - {part.images[0].url && ( - + {part.images[0] && ( +
+ +
)} {part.part_name} diff --git a/frontend/src/pages/YourParts.tsx b/frontend/src/pages/YourParts.tsx index ac71e22f..85b77779 100644 --- a/frontend/src/pages/YourParts.tsx +++ b/frontend/src/pages/YourParts.tsx @@ -1,3 +1,4 @@ +import ImageComponent from "components/files/ViewImage"; import { api, Part } from "hooks/api"; import { useAuthentication } from "hooks/auth"; import { useEffect, useState } from "react"; @@ -67,12 +68,18 @@ const YourParts = () => { {partsData.map((part) => ( navigate(`/part/${part.part_id}`)}> - {part.images[0].url && ( - + {part.images[0] && ( +
+ +
)} {part.part_name}