diff --git a/packages/frontend/src/features/upload/DrawingCanvas.tsx b/packages/frontend/src/features/upload/DrawingCanvas.tsx index 7bceab1..8c0972a 100644 --- a/packages/frontend/src/features/upload/DrawingCanvas.tsx +++ b/packages/frontend/src/features/upload/DrawingCanvas.tsx @@ -1,5 +1,5 @@ import { Flex, styled } from "#styled-system/jsx"; -import { useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; export const DrawingCanvas = ({ imageUrl }: { imageUrl: string }) => { const canvasRef = useRef(null); @@ -64,6 +64,10 @@ export const DrawingCanvas = ({ imageUrl }: { imageUrl: string }) => { img.src = imageUrl; }; + useEffect(() => { + clearCanvas(); + }, [imageUrl]); + return ( { const [statusMap, setStatusMap] = useState>({}); + const [selectedPicture, setSelectedPicture] = useState<{ id: string; url: string } | null>(null); const ref = useRef(null); + console.log(selectedPicture); + const onChange = async (e: ChangeEvent) => { const picturesStore = getPicturesStore(); const toUploadStore = getToUploadStore(); @@ -50,6 +60,9 @@ export const UploadImage = ({ reportId }: { reportId: string }) => { return ( <> + + {selectedPicture ? : null} + - + ); }; const broadcastChannel = new BroadcastChannel("sw-messages"); -const ReportPictures = ({ statusMap }: { statusMap: Record }) => { +const ReportPictures = ({ + statusMap, + setSelectedPicture, +}: { + statusMap: Record; + setSelectedPicture: (props: { id: string; url: string }) => void; +}) => { const form = useFormContext(); const reportId = form.getValues().id; @@ -93,7 +112,13 @@ const ReportPictures = ({ statusMap }: { statusMap: Record }) => {/* */} {pictures?.map((picture, index) => ( - + ))} {/* */} @@ -120,7 +145,17 @@ const mergePictureArrays = (a: Tmp_pictures[], b: Pictures[]) => { return Array.from(map.values()).sort(sortByDate); }; -const PictureThumbnail = ({ picture, index, status }: { picture: Pictures; index: number; status?: string }) => { +const PictureThumbnail = ({ + picture, + index, + status, + setSelectedPicture, +}: { + picture: Pictures; + index: number; + status?: string; + setSelectedPicture: (props: { id: string; url: string }) => void; +}) => { const deletePictureMutation = useMutation(async () => { await deleteImageFromIdb(picture.id); await db.tmp_pictures.delete({ where: { id: picture.id } }).catch(() => {}); @@ -169,6 +204,17 @@ const PictureThumbnail = ({ picture, index, status }: { picture: Pictures; index backgroundSize="cover" > + { + setSelectedPicture({ id: picture.id, url: bgUrl! }); + modal.open(); + }} + borderLeft="1px solid #DFDFDF" + > +