Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fin

Manav Rathid492a0e69512
diff --git a/web/packages/new/photos/components/PhotoViewer.tsx b/web/packages/new/photos/components/PhotoViewer.tsx
index 4455295766..8574cbc9d9 100644
--- a/web/packages/new/photos/components/PhotoViewer.tsx
+++ b/web/packages/new/photos/components/PhotoViewer.tsx
@@ -1,25 +1,14 @@
+import { InlineErrorIndicator } from "@/base/components/ErrorIndicator";
import { TitledMiniDialog } from "@/base/components/MiniDialog";
import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";
+import { LoadingButton } from "@/base/components/mui/LoadingButton";
import type { ModalVisibilityProps } from "@/base/components/utils/modal";
+import log from "@/base/log";
+import { Stack, Typography, type ModalProps } from "@mui/material";
import { t } from "i18next";
+import { useState } from "react";
import { aboveGalleryContentZ } from "./utils/z-index";
-// const confirmTrashFile = (file: EnteFile) => {
-// if (!file || !isOwnFile || isTrashCollection) {
-// return;
-// }
-// showMiniDialog({
-//
-// 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.
@@ -39,22 +28,68 @@ type ConfirmDeleteFileDialogProps = ModalVisibilityProps & {
*/
export const ConfirmDeleteFileDialog: React.FC<
ConfirmDeleteFileDialogProps
-> = ({ onConfirm, ...visibilityProps }) => (
- <TitledMiniDialog
- {...visibilityProps}
- title={t("trash_file_title")}
- sx={(theme) => ({
- zIndex: aboveGalleryContentZ,
- // See: [Note: Lighter backdrop for overlays on photo viewer]
- ...theme.applyStyles("light", {
- ".MuiBackdrop-root": {
- backgroundColor: theme.vars.palette.backdrop.faint,
- },
- }),
- })}
- >
- <FocusVisibleButton fullWidth onClick={onConfirm}>
- {"Test"}
- </FocusVisibleButton>
- </TitledMiniDialog>
-);
+> = ({ open, onClose, onConfirm }) => {
+ const [phase, setPhase] = useState<"loading" | "failed" | undefined>();
+
+ const resetPhaseAndClose = () => {
+ setPhase(undefined);
+ onClose();
+ };
+
+ const handleClick = async () => {
+ setPhase("loading");
+ try {
+ await onConfirm();
+ resetPhaseAndClose();
+ } catch (e) {
+ log.error(e);
+ setPhase("failed");
+ }
+ };
+ const handleClose: ModalProps["onClose"] = (_, reason) => {
+ // Ignore backdrop clicks when we're processing the user request.
+ if (phase == "loading") return;
+ resetPhaseAndClose();
+ };
+
+ return (
+ <TitledMiniDialog
+ open={open}
+ onClose={handleClose}
+ title={t("trash_file_title")}
+ sx={(theme) => ({
+ zIndex: aboveGalleryContentZ,
+ // See: [Note: Lighter backdrop for overlays on photo viewer]
+ ...theme.applyStyles("light", {
+ ".MuiBackdrop-root": {
+ backgroundColor: theme.vars.palette.backdrop.faint,
+ },
+ }),
+ })}
+ >
+ <Typography sx={{ color: "text.muted" }}>
+ {t("trash_file_message")}
+ </Typography>
+ <Stack sx={{ paddingBlockStart: "24px", gap: "8px" }}>
+ {phase == "failed" && <InlineErrorIndicator />}
+ <LoadingButton
+ loading={phase == "loading"}
+ fullWidth
+ color="critical"
+ autoFocus
+ onClick={handleClick}
+ >
+ {t("move_to_trash")}
+ </LoadingButton>
+ <FocusVisibleButton
+ fullWidth
+ color="secondary"
+ disabled={phase == "loading"}
+ onClick={resetPhaseAndClose}
+ >
+ {t("cancel")}
+ </FocusVisibleButton>
+ </Stack>
+ </TitledMiniDialog>
+ );
+};