From 4558252b150b39a6ca7b7022a3915fc0dd2a1418 Mon Sep 17 00:00:00 2001 From: G Date: Sat, 1 Jun 2024 20:44:21 +0800 Subject: [PATCH] fix delete, add copy --- .../AlbumPage/AlbumPhotoPage/TopRightBar.tsx | 16 +++++++- .../src/Components/PhotoPage/TopRightBar.tsx | 15 +++++++- frontend/src/Components/Shared/PhotoPage.tsx | 3 +- frontend/src/Components/ViewPage/ViewPage.tsx | 37 +++++++++++++++---- 4 files changed, 60 insertions(+), 11 deletions(-) diff --git a/frontend/src/Components/AlbumPage/AlbumPhotoPage/TopRightBar.tsx b/frontend/src/Components/AlbumPage/AlbumPhotoPage/TopRightBar.tsx index 5e77b47..e1a1d5b 100644 --- a/frontend/src/Components/AlbumPage/AlbumPhotoPage/TopRightBar.tsx +++ b/frontend/src/Components/AlbumPage/AlbumPhotoPage/TopRightBar.tsx @@ -1,5 +1,5 @@ import { IconButton, Tooltip } from "@material-ui/core"; -import { CloudDownload, Delete, Info, LibraryAdd, Pages, RemoveCircleOutline, Search } from "@material-ui/icons"; +import { CloudDownload, Delete, FileCopy, Info, LibraryAdd, Pages, RemoveCircleOutline, Search } from "@material-ui/icons"; import { useHistory } from "react-router-dom"; @@ -28,7 +28,19 @@ export default function TopRightBar(props: any) { - + + { + e.stopPropagation(); + props.buttonFunctions.copy(props.id); + }} + > + + + + + { + e.stopPropagation(); + props.buttonFunctions.copy(props.id); + }} + > + + + {props.searchByImageEnabled && void; drawe } const viewButtonFunctions = { - delete: async (id: string) => { + delete: async (id: string, onDeletedCB: any) => { setOnDeleteDialogState({ open: true, handleClose: (confirm: boolean) => async () => { if (confirm) { + onDeletedCB(); await deletePhoto(id); await props.refresh(); } diff --git a/frontend/src/Components/ViewPage/ViewPage.tsx b/frontend/src/Components/ViewPage/ViewPage.tsx index d88c538..411c62f 100644 --- a/frontend/src/Components/ViewPage/ViewPage.tsx +++ b/frontend/src/Components/ViewPage/ViewPage.tsx @@ -203,13 +203,14 @@ export default function ViewPage(props: { photos: PhotoT[]; setViewId: (arg0: st const modifiedButtonFunctions = { ...props.buttonFunctions, delete: async (id: string) => { - if (props.photos.length === 1) history.replace((history.location.pathname.split("/").splice(0, history.location.pathname.split("/").length - 2).join("/") || "/") + queryUrl); - else if (index === 0) { - slideChange(1); - } else { - slideChange(index - 1); - } - await props.buttonFunctions.delete(id); + await props.buttonFunctions.delete(id, () => { + if (props.photos.length === 1) history.replace((history.location.pathname.split("/").splice(0, history.location.pathname.split("/").length - 2).join("/") || "/") + queryUrl); + else if (index === 0) { + slideChange(1); + } else { + slideChange(index - 1); + } + }); }, remove: async (id: string) => { if (props.photos.length === 1) history.replace((history.location.pathname.split("/").splice(0, history.location.pathname.split("/").length - 2).join("/") || "/") + queryUrl); @@ -220,6 +221,28 @@ export default function ViewPage(props: { photos: PhotoT[]; setViewId: (arg0: st localStorage.setItem("drawerOpen", drawerOpen ? "false" : "true"); setDrawerOpen(!drawerOpen); }, + copy: async (id: string) => { + const imageUrl = baseURL + "/media/" + id + + try { + const img = await fetch(imageUrl); + const imgBlob = await img.blob(); + + const mimeType = 'image/png' + const imageBlob = new Blob([imgBlob], { type: mimeType }); + + await navigator.clipboard.write([ + new ClipboardItem({ + [mimeType]: Promise.resolve(imageBlob) + }) + ]); + + } catch (err) { + console.error("Failed to copy image: ", err); + } + + + } }; const prevRef = useRef(null);