Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Alt path

Manav Rathi37774c31d74d
diff --git a/web/apps/photos/src/components/PhotoViewer/index.tsx b/web/apps/photos/src/components/PhotoViewer/index.tsx
index 4117c92609..f0d7fcae19 100644
--- a/web/apps/photos/src/components/PhotoViewer/index.tsx
+++ b/web/apps/photos/src/components/PhotoViewer/index.tsx
@@ -3,13 +3,17 @@ import { assertionFailed } from "@/base/assert";
import { Overlay } from "@/base/components/containers";
import { FilledIconButton, type ButtonishProps } from "@/base/components/mui";
import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
-import { type ModalVisibilityProps } from "@/base/components/utils/modal";
+import {
+ useModalVisibility,
+ type ModalVisibilityProps,
+} from "@/base/components/utils/modal";
import { lowercaseExtension } from "@/base/file-name";
import log from "@/base/log";
import { downloadManager } from "@/gallery/services/download";
import { fileLogID, type EnteFile } from "@/media/file";
import { FileType } from "@/media/file-type";
import { isHEICExtension, needsJPEGConversion } from "@/media/formats";
+import { ConfirmDeleteFileDialog } from "@/new/photos/components/PhotoViewer";
import { moveToTrash } from "@/new/photos/services/collection";
import { extractRawExif, parseExif } from "@/new/photos/services/exif";
import { AppContext } from "@/new/photos/types/context";
@@ -134,8 +138,7 @@ export const PhotoViewer: React.FC<PhotoViewerProps> = ({
onSelectPerson,
}) => {
const galleryContext = useContext(GalleryContext);
- const { showLoadingBar, hideLoadingBar, showMiniDialog } =
- useContext(AppContext);
+ const { showLoadingBar, hideLoadingBar } = useContext(AppContext);
const publicCollectionGalleryContext = useContext(
PublicCollectionGalleryContext,
);
@@ -183,6 +186,12 @@ export const PhotoViewer: React.FC<PhotoViewerProps> = ({
() => downloadManager.fileDownloadProgressSnapshot(),
);
+ const {
+ show: showConfirmDeleteFile,
+ props: confirmDeleteFileVisibilityProps,
+ } = useModalVisibility();
+ const [fileToDelete, setFileToDelete] = useState<EnteFile | undefined>();
+
useEffect(() => {
if (!pswpElement.current) return;
if (isOpen) {
@@ -227,7 +236,7 @@ export const PhotoViewer: React.FC<PhotoViewerProps> = ({
break;
case "Backspace":
case "Delete":
- confirmTrashFile(photoSwipe?.currItem as EnteFile);
+ confirmDeleteFile(photoSwipe?.currItem as EnteFile);
break;
case "d":
case "D":
@@ -528,20 +537,17 @@ export const PhotoViewer: React.FC<PhotoViewerProps> = ({
}
};
- const confirmTrashFile = (file: EnteFile) => {
+ const confirmDeleteFile = (file: EnteFile) => {
if (!file || !isOwnFile || isTrashCollection) {
return;
}
- showMiniDialog({
- title: t("trash_file_title"),
- message: t("trash_file_message"),
- continue: {
- text: t("move_to_trash"),
- color: "critical",
- action: () => trashFile(file),
- autoFocus: true,
- },
- });
+ setFileToDelete(file);
+ showConfirmDeleteFile();
+ };
+
+ const handleDeleteFile = async () => {
+ await trashFile(fileToDelete!);
+ setFileToDelete(undefined);
};
const handleArrowClick = (
@@ -842,7 +848,7 @@ export const PhotoViewer: React.FC<PhotoViewerProps> = ({
className="pswp__button pswp__button--custom"
title={t("delete_key")}
onClick={() => {
- confirmTrashFile(
+ confirmDeleteFile(
photoSwipe?.currItem as EnteFile,
);
}}
@@ -942,6 +948,10 @@ export const PhotoViewer: React.FC<PhotoViewerProps> = ({
</div>
</div>
</div>
+ <ConfirmDeleteFileDialog
+ {...confirmDeleteFileVisibilityProps}
+ onConfirm={handleDeleteFile}
+ />
<FileInfo
showInfo={showInfo}
handleCloseInfo={handleCloseInfo}
diff --git a/web/packages/new/photos/components/PhotoViewer.tsx b/web/packages/new/photos/components/PhotoViewer.tsx
new file mode 100644
index 0000000000..2ea1a63413
--- /dev/null
+++ b/web/packages/new/photos/components/PhotoViewer.tsx
@@ -0,0 +1,50 @@
+import { TitledMiniDialog } from "@/base/components/MiniDialog";
+import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";
+import type { ModalVisibilityProps } from "@/base/components/utils/modal";
+import { aboveGalleryContentZ } from "./utils/z-index";
+
+// const confirmTrashFile = (file: EnteFile) => {
+// if (!file || !isOwnFile || isTrashCollection) {
+// return;
+// }
+// showMiniDialog({
+// title: t("trash_file_title"),
+// message: t("trash_file_message"),
+// continue: {
+// text: t("move_to_trash"),
+// color: "critical",
+// action: () => trashFile(file),
+// autoFocus: true,
+// },
+// });
+// };
+
+type ConfirmDeleteFileDialogProps = ModalVisibilityProps & {
+ /**
+ * Called when the user confirms the deletion.
+ *
+ * The delete button will show an activity indicator until this async
+ * operation completes.
+ */
+ onConfirm: () => Promise<void>;
+};
+
+/**
+ * A bespoke variant of AttributedMiniDialog for use by the delete file
+ * confirmation prompt that we show in the image viewer.
+ *
+ * - It auto focuses the primary action.
+ * - It uses a lighter backdrop in light mode.
+ */
+export const ConfirmDeleteFileDialog: React.FC<
+ ConfirmDeleteFileDialogProps
+> = ({ onConfirm, ...visibilityProps }) => (
+ <TitledMiniDialog
+ {...visibilityProps}
+ sx={{ zIndex: aboveGalleryContentZ }}
+ >
+ <FocusVisibleButton fullWidth onClick={onConfirm}>
+ {"Test"}
+ </FocusVisibleButton>
+ </TitledMiniDialog>
+);