Skip to content

armgit / ente

Public Imported from GitHub
0

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

[web] Limit refreshed delete dialog to the Photos gallery

Aswin Asok6b6462285dff
diff --git a/web/apps/photos/src/components/SelectedFileOptions.tsx b/web/apps/photos/src/components/SelectedFileOptions.tsx
index 633890da92..2580303a50 100644
--- a/web/apps/photos/src/components/SelectedFileOptions.tsx
+++ b/web/apps/photos/src/components/SelectedFileOptions.tsx
@@ -1,5 +1,6 @@
import type { CollectionSelectorAttributes } from "@/components/CollectionSelector";
import type { GalleryBarMode } from "@/components/gallery/reducer";
+import { trashFilesDialogAttributes } from "@/components/gallery/trash-files-dialog";
import {
getAvailableFileActions,
type FileContextAction,
@@ -30,7 +31,6 @@ import { Box, Button, IconButton, Tooltip, Typography } from "@mui/material";
import { SpacedRow } from "ente-base/components/containers";
import type { ButtonishProps } from "ente-base/components/mui";
import { useBaseContext } from "ente-base/context";
-import { trashFilesDialogAttributes } from "ente-gallery/components/trash-files-dialog";
import type { Collection } from "ente-media/collection";
import type { CollectionSummary } from "ente-new/photos/services/collection-summary";
import { t } from "i18next";
diff --git a/web/packages/gallery/components/trash-files-dialog.tsx b/web/apps/photos/src/components/gallery/trash-files-dialog.tsx
similarity index 94%
rename from web/packages/gallery/components/trash-files-dialog.tsx
rename to web/apps/photos/src/components/gallery/trash-files-dialog.tsx
index 126f3e1e82..6f999724ad 100644
--- a/web/packages/gallery/components/trash-files-dialog.tsx
+++ b/web/apps/photos/src/components/gallery/trash-files-dialog.tsx
@@ -3,7 +3,7 @@
import { Box } from "@mui/material";
import type { MiniDialogAttributes } from "ente-base/components/MiniDialog";
import { t } from "i18next";
-import warningRed from "./assets/warning-red.png";
+import warningRed from "./warning-red.png";
export const trashFilesDialogAttributes = (
count: number,
diff --git a/web/packages/gallery/components/assets/warning-red.png b/web/apps/photos/src/components/gallery/warning-red.png
similarity index 100%
rename from web/packages/gallery/components/assets/warning-red.png
rename to web/apps/photos/src/components/gallery/warning-red.png
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 982f4151da..b27477acc1 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -47,6 +47,7 @@ import {
useGalleryReducer,
type GalleryBarMode,
} from "@/components/gallery/reducer";
+import { trashFilesDialogAttributes } from "@/components/gallery/trash-files-dialog";
import { Sidebar } from "@/components/sidebar/Sidebar";
import {
notifyOthersFilesDialogAttributes,
@@ -91,7 +92,6 @@ import { initContacts, pullContacts } from "ente-contacts";
import { DownloadStatusNotifications } from "ente-gallery/components/DownloadStatusNotifications";
import { FullScreenDropZone } from "ente-gallery/components/FullScreenDropZone";
import type { UploadTypeSelectorIntent } from "ente-gallery/components/Upload";
-import { trashFilesDialogAttributes } from "ente-gallery/components/trash-files-dialog";
import { useSaveGroups } from "ente-gallery/components/utils/save-groups";
import type { FileViewerInitialSidebar } from "ente-gallery/components/viewer/FileViewer";
import type { Collection } from "ente-media/collection";
diff --git a/web/apps/photos/src/pages/large-files.tsx b/web/apps/photos/src/pages/large-files.tsx
index 69c9fef9f5..5e123e6592 100644
--- a/web/apps/photos/src/pages/large-files.tsx
+++ b/web/apps/photos/src/pages/large-files.tsx
@@ -25,7 +25,6 @@ import { ActivityIndicator } from "ente-base/components/mui/ActivityIndicator";
import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
import { useBaseContext } from "ente-base/context";
import log from "ente-base/log";
-import { trashFilesDialogAttributes } from "ente-gallery/components/trash-files-dialog";
import { FileViewer } from "ente-gallery/components/viewer/FileViewer";
import { formattedByteSize } from "ente-gallery/utils/units";
import {
@@ -91,7 +90,8 @@ const Page: React.FC = () => {
const handleDeleteFiles = useCallback(() => {
showMiniDialog({
- ...trashFilesDialogAttributes(state.selectedCount),
+ title: t("trash_files_title"),
+ message: t("trash_files_message"),
continue: {
text: t("move_to_trash"),
color: "critical",
@@ -112,7 +112,7 @@ const Page: React.FC = () => {
},
},
});
- }, [showMiniDialog, onGenericError, state.largeFiles, state.selectedCount]);
+ }, [showMiniDialog, onGenericError, state.largeFiles]);
const handleOpenViewer = useCallback(
(index: number) => {
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsx
index c87dbd848f..8e131fb741 100644
--- a/web/packages/gallery/components/viewer/FileViewer.tsx
+++ b/web/packages/gallery/components/viewer/FileViewer.tsx
@@ -15,14 +15,19 @@ import {
DialogTitle,
Menu,
MenuItem,
+ Stack,
styled,
Typography,
+ type ModalProps,
} from "@mui/material";
import type { LocalUser } from "ente-accounts/services/user";
import { isDesktop } from "ente-base/app";
import { SpacedRow } from "ente-base/components/containers";
-import { AttributedMiniDialog } from "ente-base/components/MiniDialog";
+import { InlineErrorIndicator } from "ente-base/components/ErrorIndicator";
+import { TitledMiniDialog } from "ente-base/components/MiniDialog";
import { DialogCloseIconButton } from "ente-base/components/mui/DialogCloseIconButton";
+import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
+import { LoadingButton } from "ente-base/components/mui/LoadingButton";
import { useInterval, useIsSmallWidth } from "ente-base/components/utils/hooks";
import type { ModalVisibilityProps } from "ente-base/components/utils/modal";
import { useBaseContext } from "ente-base/context";
@@ -34,7 +39,6 @@ import {
type FileInfoExif,
type FileInfoProps,
} from "ente-gallery/components/FileInfo";
-import { trashFilesDialogAttributes } from "ente-gallery/components/trash-files-dialog";
import type { Collection } from "ente-media/collection";
import {
fileFileName,
@@ -1930,25 +1934,10 @@ export const FileViewer: React.FC<FileViewerProps> = ({
</Typography>
</MoreMenuItem>
</MoreMenu>
- <AttributedMiniDialog
+ <ConfirmDeleteFileDialog
open={openConfirmDelete}
onClose={handleConfirmDeleteClose}
- attributes={{
- ...trashFilesDialogAttributes(1),
- continue: {
- text: t("move_to_trash"),
- color: "critical",
- autoFocus: true,
- action: handleDelete,
- },
- }}
- sx={(theme) => ({
- ...theme.applyStyles("light", {
- ".MuiBackdrop-root": {
- backgroundColor: theme.vars.palette.backdrop.faint,
- },
- }),
- })}
+ onConfirm={handleDelete}
/>
{handleSaveEditedCopy && (
<ImageEditorOverlay
@@ -2005,6 +1994,78 @@ const MoreMenuItemTitle: React.FC<React.PropsWithChildren> = ({ children }) => (
<Typography sx={{ fontWeight: "medium" }}>{children}</Typography>
);
+type ConfirmDeleteFileDialogProps = ModalVisibilityProps & {
+ onConfirm: () => Promise<void>;
+};
+
+const ConfirmDeleteFileDialog: React.FC<ConfirmDeleteFileDialogProps> = ({
+ 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) => {
+ if (reason == "backdropClick" && phase == "loading") return;
+ resetPhaseAndClose();
+ };
+
+ return (
+ <TitledMiniDialog
+ open={open}
+ onClose={handleClose}
+ title={t("trash_file_title")}
+ sx={(theme) => ({
+ ...theme.applyStyles("light", {
+ ".MuiBackdrop-root": {
+ backgroundColor: theme.vars.palette.backdrop.faint,
+ },
+ }),
+ })}
+ >
+ <Typography sx={{ color: "text.muted" }}>
+ {t("trash_file_message")}
+ </Typography>
+ <Stack sx={{ pt: 3, gap: 1 }}>
+ {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>
+ );
+};
+
type ShortcutsProps = ModalVisibilityProps &
Pick<FileViewerProps, "disableDownload"> & { haveUser: boolean };