aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/AvatarCrop/AvatarCrop.tsx9
-rw-r--r--src/components/ModalScreen/ModalScreen.tsx12
2 files changed, 15 insertions, 6 deletions
diff --git a/src/components/AvatarCrop/AvatarCrop.tsx b/src/components/AvatarCrop/AvatarCrop.tsx
index e344edd..ef6d9c8 100644
--- a/src/components/AvatarCrop/AvatarCrop.tsx
+++ b/src/components/AvatarCrop/AvatarCrop.tsx
@@ -6,8 +6,8 @@ import ModalScreen from "../ModalScreen/ModalScreen";
import { getCroppedImg } from './canvasUtils'
interface PropTypes {
- location?: any;
avatarToCrop: string;
+ setAvatarToCrop: (src: string) => void;
callback: (file: File) => void;
}
@@ -23,7 +23,7 @@ const useStyles = makeStyles(theme => ({
}
}));
-const AvatarCrop: React.FC<PropTypes> = ({location, avatarToCrop, callback}) => {
+const AvatarCrop: React.FC<PropTypes> = ({ avatarToCrop, setAvatarToCrop, callback }) => {
const classes = useStyles();
const [crop, setCrop] = useState({x: 0, y: 0});
const [zoom, setZoom] = useState(1);
@@ -42,12 +42,17 @@ const AvatarCrop: React.FC<PropTypes> = ({location, avatarToCrop, callback}) =>
}
}, [avatarToCrop, croppedAreaPixels]);
+ const handleCloseModal = useCallback( () => {
+ setAvatarToCrop('');
+ },[]);
+
return (
<ModalScreen
title="Choose area"
actionIcon={<SendIcon />}
handleAction={handleLoadCroppedImage}
isActionDisabled={false}
+ handleCloseModal={handleCloseModal}
>
<div className={classes.cropContainer}>
<Cropper
diff --git a/src/components/ModalScreen/ModalScreen.tsx b/src/components/ModalScreen/ModalScreen.tsx
index 0f2c96f..61cf44a 100644
--- a/src/components/ModalScreen/ModalScreen.tsx
+++ b/src/components/ModalScreen/ModalScreen.tsx
@@ -20,6 +20,7 @@ interface PropTypes {
actionIcon?: JSX.Element;
handleAction?: () => void;
isActionDisabled?: boolean;
+ handleCloseModal: ()=> void;
}
const useStyles = makeStyles(theme => ({
@@ -42,24 +43,27 @@ const Transition = React.forwardRef((
ref: React.Ref<unknown>
) => <Slide direction="left" ref={ref} {...props} />);
-const ModalScreen: React.FC<PropTypes> = ({ title, actionIcon, handleAction, isActionDisabled, children }) => {
+const ModalScreen: React.FC<PropTypes> = ({ title, actionIcon, handleAction, isActionDisabled, handleCloseModal, children }) => {
const [isOpen, setIsOpen] = useState<boolean>(true);
const classes = useStyles();
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
const history = useHistory();
- const handleClose = useCallback(() => history.goBack(), [history]);
+
+ const handleClose = useCallback(() => setIsOpen(false), [setIsOpen]);
+ const onExited = useCallback(handleCloseModal, [history, handleAction]);
const handleClickAction = useCallback(async () => {
if (handleAction) await handleAction();
- return window.location.pathname.includes('/profile') ? null : handleClose();
+ return handleClose();
}, [handleAction, handleClose]);
return (
<Dialog
- open={true}
+ open={isOpen}
onClose={handleClose}
+ onExited={onExited}
TransitionComponent={Transition}
PaperProps={{ className: classes.root }}
fullScreen={isMobile}