From 4471fef74dfe312a8cf6a1440f5a703e897af136 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 7 Oct 2020 23:25:52 +0300 Subject: feat: wire modal routes --- src/containers/Page/Page.tsx | 15 ++++++++----- src/containers/Page/Router.tsx | 48 +++++++++++++++++++++++++++++------------- 2 files changed, 43 insertions(+), 20 deletions(-) (limited to 'src/containers') diff --git a/src/containers/Page/Page.tsx b/src/containers/Page/Page.tsx index 7df62cd..51b6d21 100644 --- a/src/containers/Page/Page.tsx +++ b/src/containers/Page/Page.tsx @@ -5,11 +5,14 @@ import { SnackbarProvider } from 'notistack'; import { ErrorBoundary } from 'react-error-boundary'; import { useHistory } from 'react-router-dom'; -import Router from './Router'; +import Router, { LocationState } from './Router'; import DynoWaiter from './DynoWaiter'; import Loading from '../../components/Loading/Loading'; import EmptyState from '../../components/EmptyState/EmptyState'; +interface HistoryChange { + state?: LocationState | null; +} const useStyles = makeStyles(theme => ({ root: { @@ -32,11 +35,13 @@ const Page: React.FC = () => { const history = useHistory(); const isMobile = useMediaQuery(theme.breakpoints.down('sm')); - useEffect(() => { - return history.listen(() => { + useEffect(() => history.listen((update: HistoryChange) => { + console.log(update) + if (!update.state?.background) { + console.log('scrolling') window.scrollTo(0, 0); - }); - }, [history]); + } + }), [history]); return ( import('../Profile/Profile')); const Feed = React.lazy(() => import('../Feed/Feed')); @@ -7,20 +10,35 @@ const Login = React.lazy(() => import('../Login/Login')); const Registration = React.lazy(() => import('../Registration/Registration')); const Home = React.lazy(() => import('../Home/Home')); const Notifications = React.lazy(() => import('../Notifications/Notifications')); -const PollCreation = React.lazy(() => import('../PollCreation/PollCreation')); - - -const Router: React.FC = React.memo(() => ( - - - - - - - - - -)); + +export interface LocationState { + background?: Location; +} + +const Router: React.FC = React.memo(() => { + const location = useLocation(); + const background = location.state && location.state.background; + + const ModalSwitch = ( + + + + ); + + return ( + <> + {background && ModalSwitch} + + + + + + + + + + ); +}); export default Router; -- cgit v1.2.3 From a283d4310c11f03fe9ff889c6274798b70cf6a19 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 7 Oct 2020 23:51:45 +0300 Subject: feat: create ModalScreen component --- src/containers/Page/Page.tsx | 6 +-- src/containers/PollCreation/PollCreation.tsx | 58 +++++++++++++--------------- 2 files changed, 27 insertions(+), 37 deletions(-) (limited to 'src/containers') diff --git a/src/containers/Page/Page.tsx b/src/containers/Page/Page.tsx index 51b6d21..b7e1938 100644 --- a/src/containers/Page/Page.tsx +++ b/src/containers/Page/Page.tsx @@ -36,11 +36,7 @@ const Page: React.FC = () => { const isMobile = useMediaQuery(theme.breakpoints.down('sm')); useEffect(() => history.listen((update: HistoryChange) => { - console.log(update) - if (!update.state?.background) { - console.log('scrolling') - window.scrollTo(0, 0); - } + if (!update.state?.background) window.scrollTo(0, 0); }), [history]); return ( diff --git a/src/containers/PollCreation/PollCreation.tsx b/src/containers/PollCreation/PollCreation.tsx index ecc6757..079c79f 100644 --- a/src/containers/PollCreation/PollCreation.tsx +++ b/src/containers/PollCreation/PollCreation.tsx @@ -5,7 +5,6 @@ import { makeStyles } from '@material-ui/core/styles'; import { Button, Card, - Divider, Container, LinearProgress } from '@material-ui/core'; @@ -13,16 +12,12 @@ import { useSnackbar } from 'notistack'; import useS3Preupload from './useS3Preupload'; import ImageInput from './ImageInput'; -import UserStrip from '../../components/UserStrip/UserStrip'; +import ModalScreen from '../../components/ModalScreen/ModalScreen'; import { post } from '../../requests'; -import { useAuth } from '../../hooks/useAuth'; import { useFeed } from '../../hooks/APIClient'; const useStyles = makeStyles(theme => ({ - root: { - marginBottom: theme.spacing(4) - }, images: { height: theme.spacing(50), display: 'flex' @@ -34,7 +29,6 @@ const PollCreation: React.FC = () => { const classes = useStyles(); const history = useHistory(); const { enqueueSnackbar } = useSnackbar(); - const { user } = useAuth(); const { mutate: updateFeed } = useFeed(); const { file: left, @@ -71,31 +65,31 @@ const PollCreation: React.FC = () => { }; return ( - - - {user && } - -
- - -
- { - leftProgress || rightProgress - ? - : ( - - ) - } -
-
+ + + +
+ + +
+ { + leftProgress || rightProgress + ? + : ( + + ) + } +
+
+
); }; -- cgit v1.2.3 From 0397903b9046e062fc6adb367183e2169bd4b4b6 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Oct 2020 12:58:45 +0300 Subject: feat: return UserStrip to PollCreation --- src/containers/PollCreation/PollCreation.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/containers') diff --git a/src/containers/PollCreation/PollCreation.tsx b/src/containers/PollCreation/PollCreation.tsx index 079c79f..b7ee00a 100644 --- a/src/containers/PollCreation/PollCreation.tsx +++ b/src/containers/PollCreation/PollCreation.tsx @@ -13,8 +13,10 @@ import { useSnackbar } from 'notistack'; import useS3Preupload from './useS3Preupload'; import ImageInput from './ImageInput'; import ModalScreen from '../../components/ModalScreen/ModalScreen'; +import UserStrip from '../../components/UserStrip/UserStrip'; import { post } from '../../requests'; import { useFeed } from '../../hooks/APIClient'; +import { useAuth } from '../../hooks/useAuth'; const useStyles = makeStyles(theme => ({ @@ -28,6 +30,7 @@ const useStyles = makeStyles(theme => ({ const PollCreation: React.FC = () => { const classes = useStyles(); const history = useHistory(); + const { user } = useAuth(); const { enqueueSnackbar } = useSnackbar(); const { mutate: updateFeed } = useFeed(); const { @@ -67,7 +70,8 @@ const PollCreation: React.FC = () => { return ( - + + {user && }
-- cgit v1.2.3 From 4a86d5c3f0b023c6e4e7862f2a49301ef8b4d3f7 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 8 Oct 2020 13:33:39 +0300 Subject: feat: allow reaching modal routes from outside --- src/containers/Page/Router.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/containers') diff --git a/src/containers/Page/Router.tsx b/src/containers/Page/Router.tsx index abf8f00..7c3a418 100644 --- a/src/containers/Page/Router.tsx +++ b/src/containers/Page/Router.tsx @@ -27,7 +27,7 @@ const Router: React.FC = React.memo(() => { return ( <> - {background && ModalSwitch} + {ModalSwitch} -- cgit v1.2.3