From 7ef4b53fdb63731e2d5e1f68d693661fa7d0bdb7 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 10 Oct 2022 13:29:44 +0530 Subject: [PATCH] add delete current file option to photoswipe --- src/components/PhotoSwipe/index.tsx | 31 ++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/components/PhotoSwipe/index.tsx b/src/components/PhotoSwipe/index.tsx index 19a6f6bcb..8049fc270 100644 --- a/src/components/PhotoSwipe/index.tsx +++ b/src/components/PhotoSwipe/index.tsx @@ -28,6 +28,9 @@ import InfoIcon from '@mui/icons-material/InfoOutlined'; import FavoriteIcon from '@mui/icons-material/FavoriteRounded'; import FavoriteBorderIcon from '@mui/icons-material/FavoriteBorderRounded'; import ChevronRight from '@mui/icons-material/ChevronRight'; +import DeleteIcon from '@mui/icons-material/Delete'; +import { trashFiles } from 'services/fileService'; +import { getTrashFileMessage } from 'utils/ui'; interface Iprops { isOpen: boolean; @@ -38,6 +41,8 @@ interface Iprops { id?: string; className?: string; favItemIds: Set; + deletedFileIds: Set; + setDeletedFileIds?: (value: Set) => void; isSharedCollection: boolean; isTrashCollection: boolean; enableDownload: boolean; @@ -262,6 +267,19 @@ function PhotoSwipe(props: Iprops) { needUpdate.current = true; }; + const trashFile = async (file: EnteFile) => { + const { deletedFileIds, setDeletedFileIds } = props; + deletedFileIds.add(file.id); + setDeletedFileIds(deletedFileIds); + await trashFiles([file]); + setIsFav(true); + needUpdate.current = true; + photoSwipe.next(); + }; + + const confirmTrashFile = (file: EnteFile) => + appContext.setDialogMessage(getTrashFileMessage(() => trashFile(file))); + const updateItems = (items = []) => { if (photoSwipe) { photoSwipe.items.length = 0; @@ -269,7 +287,9 @@ function PhotoSwipe(props: Iprops) { photoSwipe.items.push(item); }); photoSwipe.invalidateCurrItems(); - // photoSwipe.updateSize(true); + if ((photoSwipe as any).isOpen()) { + photoSwipe.updateSize(true); + } } }; @@ -390,6 +410,15 @@ function PhotoSwipe(props: Iprops) { )} )} + {!props.isSharedCollection && (