From 5eba5c1ffcdaee9a81e965f0570b00dd26bb38c6 Mon Sep 17 00:00:00 2001 From: ilyayudovin Date: Thu, 29 Oct 2020 21:28:52 +0300 Subject: Wait till modal slide right on close --- src/components/AvatarCrop/AvatarCrop.tsx | 9 +++++++-- src/components/ModalScreen/ModalScreen.tsx | 12 ++++++++---- src/containers/PollCreation/PollCreation.tsx | 8 +++++++- src/containers/Profile/ProfileInfo.tsx | 2 +- 4 files changed, 23 insertions(+), 8 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 = ({location, avatarToCrop, callback}) => { +const AvatarCrop: React.FC = ({ 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 = ({location, avatarToCrop, callback}) => } }, [avatarToCrop, croppedAreaPixels]); + const handleCloseModal = useCallback( () => { + setAvatarToCrop(''); + },[]); + return ( } handleAction={handleLoadCroppedImage} isActionDisabled={false} + handleCloseModal={handleCloseModal} >
void; isActionDisabled?: boolean; + handleCloseModal: ()=> void; } const useStyles = makeStyles(theme => ({ @@ -42,24 +43,27 @@ const Transition = React.forwardRef(( ref: React.Ref ) => ); -const ModalScreen: React.FC = ({ title, actionIcon, handleAction, isActionDisabled, children }) => { +const ModalScreen: React.FC = ({ title, actionIcon, handleAction, isActionDisabled, handleCloseModal, children }) => { const [isOpen, setIsOpen] = useState(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 ( ({ images: { @@ -32,6 +33,7 @@ const useStyles = makeStyles(theme => ({ const PollCreation: React.FC = () => { const [description, setDescription] = useState(''); const classes = useStyles(); + const history = useHistory(); const { enqueueSnackbar } = useSnackbar(); const { user } = useAuth(); const { mutate: updateFeed } = useFeed(); @@ -71,6 +73,9 @@ const PollCreation: React.FC = () => { } }; + const handleClose = useCallback(() => history.goBack(), [history]); + + const isSubmitting = useMemo(() => leftProgress + rightProgress > 0, [leftProgress, rightProgress]); return ( @@ -79,6 +84,7 @@ const PollCreation: React.FC = () => { actionIcon={} handleAction={handleSubmit} isActionDisabled={!(left && right) || isSubmitting} + handleCloseModal={handleClose} > diff --git a/src/containers/Profile/ProfileInfo.tsx b/src/containers/Profile/ProfileInfo.tsx index 763a077..b71e6db 100644 --- a/src/containers/Profile/ProfileInfo.tsx +++ b/src/containers/Profile/ProfileInfo.tsx @@ -129,7 +129,7 @@ const ProfileInfo: React.FC = ({ return (
{ - avatarToCrop && + avatarToCrop && } { !userInfo -- cgit v1.2.3