From 4471fef74dfe312a8cf6a1440f5a703e897af136 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Wed, 7 Oct 2020 23:25:52 +0300
Subject: feat: wire modal routes

---
 src/containers/Page/Router.tsx | 48 +++++++++++++++++++++++++++++-------------
 1 file changed, 33 insertions(+), 15 deletions(-)

(limited to 'src/containers/Page/Router.tsx')

diff --git a/src/containers/Page/Router.tsx b/src/containers/Page/Router.tsx
index 7067eea..abf8f00 100644
--- a/src/containers/Page/Router.tsx
+++ b/src/containers/Page/Router.tsx
@@ -1,5 +1,8 @@
 import React from 'react';
-import { Switch, Route } from 'react-router-dom';
+import { Switch, Route, useLocation } from 'react-router-dom';
+import { Location } from 'history';
+
+import PollCreation from '../PollCreation/PollCreation';
 
 const Profile = React.lazy(() => 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(() => (
-  <Switch>
-    <Route exact path="/" component={Home} />
-    <Route exact path="/login" component={Login} />
-    <Route exact path="/registration" component={Registration} />
-    <Route exact path="/feed" component={Feed} />
-    <Route exact path="/notifications" component={Notifications} />
-    <Route exact path="/new" component={PollCreation} />
-    <Route path="/profile/:username" component={Profile} />
-  </Switch>
-));
+
+export interface LocationState {
+  background?: Location;
+}
+
+const Router: React.FC = React.memo(() => {
+  const location = useLocation<LocationState>();
+  const background = location.state && location.state.background;
+
+  const ModalSwitch = (
+    <Switch>
+      <Route path="/new" component={PollCreation} />
+    </Switch>
+  );
+
+  return (
+    <>
+      {background && ModalSwitch}
+      <Switch location={background || location}>
+        <Route exact path="/" component={Home} />
+        <Route exact path="/login" component={Login} />
+        <Route exact path="/registration" component={Registration} />
+        <Route exact path="/notifications" component={Notifications} />
+        <Route path="/feed" component={Feed} />
+        <Route path="/profile/:username" component={Profile} />
+      </Switch>
+    </>
+  );
+});
 
 
 export default Router;
-- 
cgit v1.2.3


From 4a86d5c3f0b023c6e4e7862f2a49301ef8b4d3f7 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
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/Page/Router.tsx')

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}
       <Switch location={background || location}>
         <Route exact path="/" component={Home} />
         <Route exact path="/login" component={Login} />
-- 
cgit v1.2.3

