add delete current file option to photoswipe
This commit is contained in:
parent
27277d075d
commit
7ef4b53fdb
|
@ -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<number>;
|
||||
deletedFileIds: Set<number>;
|
||||
setDeletedFileIds?: (value: Set<number>) => 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) {
|
|||
)}
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
className="pswp__button pswp__button--custom"
|
||||
onClick={() => {
|
||||
confirmTrashFile(
|
||||
photoSwipe?.currItem as EnteFile
|
||||
);
|
||||
}}>
|
||||
<DeleteIcon fontSize="small" />
|
||||
</button>
|
||||
{!props.isSharedCollection && (
|
||||
<button
|
||||
className="pswp__button pswp__button--custom"
|
||||
|
|
Loading…
Reference in a new issue