Skip to content

armgit / ente

Public Imported from GitHub
0

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

use appContext message box for close confirmation message

Abhinavea01f246864b
diff --git a/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/AreYouSureCloseDialog.tsx b/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/AreYouSureCloseDialog.tsx
deleted file mode 100644
index 169a6fe2e7..0000000000
--- a/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/AreYouSureCloseDialog.tsx
+++ /dev/null
@@ -1,42 +0,0 @@
-import { Button, Stack, Typography } from '@mui/material';
-import DialogBoxV2 from 'components/DialogBoxV2';
-import EnteButton from 'components/EnteButton';
-import { t } from 'i18next';
-
-interface IProps {
- open: boolean;
- onClose: () => void;
- doClose: () => void;
-}
-
-const AreYouSureCloseDialog = (props: IProps) => {
- return (
- <>
- <DialogBoxV2
- open={props.open}
- onClose={props.onClose}
- attributes={{
- title: t('CONFIRM_EDITOR_CLOSE_MESSAGE'),
- }}>
- <Typography>{t('CONFIRM_EDITOR_CLOSE_DESCRIPTION')}</Typography>
- <Stack spacing={'8px'}>
- <EnteButton
- type="submit"
- size="large"
- color="critical"
- onClick={props.doClose}>
- {t('CLOSE')}
- </EnteButton>
- <Button
- size="large"
- color={'secondary'}
- onClick={props.onClose}>
- {t('CANCEL')}
- </Button>
- </Stack>
- </DialogBoxV2>
- </>
- );
-};
-
-export default AreYouSureCloseDialog;
diff --git a/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx b/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
index f9951b4328..9e31deab66 100644
--- a/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
+++ b/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
@@ -15,6 +15,7 @@ import {
Dispatch,
SetStateAction,
MutableRefObject,
+ useContext,
} from 'react';
import { EnteFile } from 'types/file';
@@ -35,11 +36,12 @@ import uploadManager from 'services/upload/uploadManager';
import { getLocalCollections } from 'services/collectionService';
import CloudUploadIcon from '@mui/icons-material/CloudUpload';
import MenuItemDivider from 'components/Menu/MenuItemDivider';
-import AreYouSureCloseDialog from './AreYouSureCloseDialog';
import { t } from 'i18next';
import { EnteDrawer } from 'components/EnteDrawer';
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
import MenuIcon from '@mui/icons-material/Menu';
+import { AppContext } from 'pages/_app';
+import { getEditorCloseConfirmationMessage } from 'utils/ui';
interface IProps {
file: EnteFile;
@@ -67,6 +69,7 @@ const filterDefaultValues = {
};
const ImageEditorOverlay = (props: IProps) => {
+ const appContext = useContext(AppContext);
// const [originalWidth, originalHeight] = [props.file?.w, props.file?.h];
const canvasRef = useRef<HTMLCanvasElement | null>(null);
@@ -97,8 +100,6 @@ const ImageEditorOverlay = (props: IProps) => {
const [canvasLoading, setCanvasLoading] = useState(false);
- const [showBeforeCloseDialog, setShowBeforeCloseDialog] = useState(false);
-
const [showControlsDrawer, setShowControlsDrawer] = useState(true);
useEffect(() => {
@@ -236,6 +237,21 @@ const ImageEditorOverlay = (props: IProps) => {
canvas.toBlob(callback, mimeType);
};
+ const handleClose = () => {
+ setFileURL(null);
+ props.onClose();
+ };
+
+ const handleCloseWithConfirmation = () => {
+ if (transformationPerformed || coloursAdjusted) {
+ appContext.setDialogBoxAttributesV2(
+ getEditorCloseConfirmationMessage(handleClose)
+ );
+ } else {
+ handleClose();
+ }
+ };
+
return (
<>
{props.show && (
@@ -306,9 +322,7 @@ const ImageEditorOverlay = (props: IProps) => {
variant="persistent"
anchor="right"
open={showControlsDrawer}
- onClose={() => {
- setShowBeforeCloseDialog(true);
- }}>
+ onClose={handleCloseWithConfirmation}>
<HorizontalFlex justifyContent={'space-between'}>
<IconButton
onClick={() => {
@@ -317,17 +331,7 @@ const ImageEditorOverlay = (props: IProps) => {
<ChevronRightIcon />
</IconButton>
<IconButton
- onClick={() => {
- if (
- transformationPerformed ||
- coloursAdjusted
- ) {
- setShowBeforeCloseDialog(true);
- return;
- }
- setFileURL(null);
- props.onClose();
- }}>
+ onClick={handleCloseWithConfirmation}>
<CloseIcon />
</IconButton>
</HorizontalFlex>
@@ -478,17 +482,6 @@ const ImageEditorOverlay = (props: IProps) => {
{/* <Box> */}
{/* </Box> */}
</Backdrop>
- <AreYouSureCloseDialog
- open={showBeforeCloseDialog}
- onClose={() => {
- setShowBeforeCloseDialog(false);
- }}
- doClose={() => {
- setFileURL(null);
- props.onClose();
- setShowBeforeCloseDialog(false);
- }}
- />
</>
)}
</>
diff --git a/apps/photos/src/utils/ui/index.tsx b/apps/photos/src/utils/ui/index.tsx
index 24c853c439..d08d94858d 100644
--- a/apps/photos/src/utils/ui/index.tsx
+++ b/apps/photos/src/utils/ui/index.tsx
@@ -164,3 +164,16 @@ export const getMapDisableConfirmationDialog = (
},
close: { text: t('CANCEL') },
});
+
+export const getEditorCloseConfirmationMessage = (
+ doClose: () => void
+): DialogBoxAttributes => ({
+ title: t('CONFIRM_EDITOR_CLOSE_MESSAGE'),
+ content: t('CONFIRM_EDITOR_CLOSE_DESCRIPTION'),
+ proceed: {
+ action: doClose,
+ text: t('CLOSE'),
+ variant: 'critical',
+ },
+ close: { text: t('CANCEL') },
+});