Skip to content

Commit 4558252

Browse files
committed
fix delete, add copy
1 parent 49b2595 commit 4558252

File tree

4 files changed

+60
-11
lines changed

4 files changed

+60
-11
lines changed

frontend/src/Components/AlbumPage/AlbumPhotoPage/TopRightBar.tsx

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IconButton, Tooltip } from "@material-ui/core";
2-
import { CloudDownload, Delete, Info, LibraryAdd, Pages, RemoveCircleOutline, Search } from "@material-ui/icons";
2+
import { CloudDownload, Delete, FileCopy, Info, LibraryAdd, Pages, RemoveCircleOutline, Search } from "@material-ui/icons";
33
import { useHistory } from "react-router-dom";
44

55

@@ -28,7 +28,19 @@ export default function TopRightBar(props: any) {
2828
<Info />
2929
</IconButton>
3030
</Tooltip>
31-
31+
<Tooltip title="Copy">
32+
<IconButton
33+
className="IconButton"
34+
color="primary"
35+
aria-label="copy"
36+
onClick={(e) => {
37+
e.stopPropagation();
38+
props.buttonFunctions.copy(props.id);
39+
}}
40+
>
41+
<FileCopy />
42+
</IconButton>
43+
</Tooltip>
3244
<Tooltip title="Set as album cover">
3345
<IconButton
3446
className="IconButton"

frontend/src/Components/PhotoPage/TopRightBar.tsx

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IconButton, Tooltip } from "@material-ui/core";
2-
import { CloudDownload, Delete, Info, LibraryAdd, Search } from "@material-ui/icons";
2+
import { CloudDownload, Delete, FileCopy, Info, LibraryAdd, Search } from "@material-ui/icons";
33
import { useHistory } from "react-router-dom";
44

55
export default function TopRightBar(props: any) {
@@ -27,6 +27,19 @@ export default function TopRightBar(props: any) {
2727
<Info />
2828
</IconButton>
2929
</Tooltip>
30+
<Tooltip title="Copy">
31+
<IconButton
32+
className="IconButton"
33+
color="primary"
34+
aria-label="copy"
35+
onClick={(e) => {
36+
e.stopPropagation();
37+
props.buttonFunctions.copy(props.id);
38+
}}
39+
>
40+
<FileCopy />
41+
</IconButton>
42+
</Tooltip>
3043
{props.searchByImageEnabled &&
3144
<Tooltip title="Search for similar">
3245
<IconButton

frontend/src/Components/Shared/PhotoPage.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,12 @@ export default function PhotoPage(props: { handleDrawerToggle: () => void; drawe
358358
}
359359

360360
const viewButtonFunctions = {
361-
delete: async (id: string) => {
361+
delete: async (id: string, onDeletedCB: any) => {
362362
setOnDeleteDialogState({
363363
open: true,
364364
handleClose: (confirm: boolean) => async () => {
365365
if (confirm) {
366+
onDeletedCB();
366367
await deletePhoto(id);
367368
await props.refresh();
368369
}

frontend/src/Components/ViewPage/ViewPage.tsx

+30-7
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,14 @@ export default function ViewPage(props: { photos: PhotoT[]; setViewId: (arg0: st
203203
const modifiedButtonFunctions = {
204204
...props.buttonFunctions,
205205
delete: async (id: string) => {
206-
if (props.photos.length === 1) history.replace((history.location.pathname.split("/").splice(0, history.location.pathname.split("/").length - 2).join("/") || "/") + queryUrl);
207-
else if (index === 0) {
208-
slideChange(1);
209-
} else {
210-
slideChange(index - 1);
211-
}
212-
await props.buttonFunctions.delete(id);
206+
await props.buttonFunctions.delete(id, () => {
207+
if (props.photos.length === 1) history.replace((history.location.pathname.split("/").splice(0, history.location.pathname.split("/").length - 2).join("/") || "/") + queryUrl);
208+
else if (index === 0) {
209+
slideChange(1);
210+
} else {
211+
slideChange(index - 1);
212+
}
213+
});
213214
},
214215
remove: async (id: string) => {
215216
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
220221
localStorage.setItem("drawerOpen", drawerOpen ? "false" : "true");
221222
setDrawerOpen(!drawerOpen);
222223
},
224+
copy: async (id: string) => {
225+
const imageUrl = baseURL + "/media/" + id
226+
227+
try {
228+
const img = await fetch(imageUrl);
229+
const imgBlob = await img.blob();
230+
231+
const mimeType = 'image/png'
232+
const imageBlob = new Blob([imgBlob], { type: mimeType });
233+
234+
await navigator.clipboard.write([
235+
new ClipboardItem({
236+
[mimeType]: Promise.resolve(imageBlob)
237+
})
238+
]);
239+
240+
} catch (err) {
241+
console.error("Failed to copy image: ", err);
242+
}
243+
244+
245+
}
223246
};
224247

225248
const prevRef = useRef<HTMLDivElement>(null);

0 commit comments

Comments
 (0)