add delete current file option to photoswipe

This commit is contained in:
Abhinav 2022-10-10 13:29:44 +05:30
parent 27277d075d
commit 7ef4b53fdb

View file

@ -28,6 +28,9 @@ import InfoIcon from '@mui/icons-material/InfoOutlined';
import FavoriteIcon from '@mui/icons-material/FavoriteRounded'; import FavoriteIcon from '@mui/icons-material/FavoriteRounded';
import FavoriteBorderIcon from '@mui/icons-material/FavoriteBorderRounded'; import FavoriteBorderIcon from '@mui/icons-material/FavoriteBorderRounded';
import ChevronRight from '@mui/icons-material/ChevronRight'; 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 { interface Iprops {
isOpen: boolean; isOpen: boolean;
@ -38,6 +41,8 @@ interface Iprops {
id?: string; id?: string;
className?: string; className?: string;
favItemIds: Set<number>; favItemIds: Set<number>;
deletedFileIds: Set<number>;
setDeletedFileIds?: (value: Set<number>) => void;
isSharedCollection: boolean; isSharedCollection: boolean;
isTrashCollection: boolean; isTrashCollection: boolean;
enableDownload: boolean; enableDownload: boolean;
@ -262,6 +267,19 @@ function PhotoSwipe(props: Iprops) {
needUpdate.current = true; 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 = []) => { const updateItems = (items = []) => {
if (photoSwipe) { if (photoSwipe) {
photoSwipe.items.length = 0; photoSwipe.items.length = 0;
@ -269,7 +287,9 @@ function PhotoSwipe(props: Iprops) {
photoSwipe.items.push(item); photoSwipe.items.push(item);
}); });
photoSwipe.invalidateCurrItems(); photoSwipe.invalidateCurrItems();
// photoSwipe.updateSize(true); if ((photoSwipe as any).isOpen()) {
photoSwipe.updateSize(true);
}
} }
}; };
@ -390,6 +410,15 @@ function PhotoSwipe(props: Iprops) {
)} )}
</button> </button>
)} )}
<button
className="pswp__button pswp__button--custom"
onClick={() => {
confirmTrashFile(
photoSwipe?.currItem as EnteFile
);
}}>
<DeleteIcon fontSize="small" />
</button>
{!props.isSharedCollection && ( {!props.isSharedCollection && (
<button <button
className="pswp__button pswp__button--custom" className="pswp__button pswp__button--custom"