summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2018-09-07 13:25:55 +0300
committerAndrej Mihajlov <and@mullvad.net>2018-09-07 19:14:06 +0300
commit76097e4eadd4334b9a390be85acdebbdd3f6e706 (patch)
tree9b64e06f957100f0e6aec42489dcacded21c1782
parentbb945c76a710ecc1416531b59116dbba0483a306 (diff)
downloadmullvadvpn-76097e4eadd4334b9a390be85acdebbdd3f6e706.tar.xz
mullvadvpn-76097e4eadd4334b9a390be85acdebbdd3f6e706.zip
Remove smart routes
-rw-r--r--gui/packages/desktop/src/renderer/app.js9
-rw-r--r--gui/packages/desktop/src/renderer/routes.js121
2 files changed, 24 insertions, 106 deletions
diff --git a/gui/packages/desktop/src/renderer/app.js b/gui/packages/desktop/src/renderer/app.js
index 3384a6d3c8..4fb7952435 100644
--- a/gui/packages/desktop/src/renderer/app.js
+++ b/gui/packages/desktop/src/renderer/app.js
@@ -116,9 +116,7 @@ export default class AppRenderer {
renderView() {
return (
<Provider store={this._reduxStore}>
- <ConnectedRouter history={this._memoryHistory}>
- {makeRoutes(this._reduxStore.getState, { app: this })}
- </ConnectedRouter>
+ <ConnectedRouter history={this._memoryHistory}>{makeRoutes({ app: this })}</ConnectedRouter>
</Provider>
);
}
@@ -490,7 +488,10 @@ export default class AppRenderer {
});
// take user back to the launch screen `/` except when user is in settings.
- if (!history.location.pathname.startsWith('/settings')) {
+ if (history.location.pathname.startsWith('/settings')) {
+ // TODO: make sure that user can still access settings but returning from settings should
+ // take user to launch screen `/`.
+ } else {
actions.history.replace('/');
}
}
diff --git a/gui/packages/desktop/src/renderer/routes.js b/gui/packages/desktop/src/renderer/routes.js
index 9a93a76936..54e6cf8295 100644
--- a/gui/packages/desktop/src/renderer/routes.js
+++ b/gui/packages/desktop/src/renderer/routes.js
@@ -1,7 +1,7 @@
// @flow
import * as React from 'react';
-import { Switch, Route, Redirect } from 'react-router';
+import { Switch, Route } from 'react-router';
import TransitionContainer from './components/TransitionContainer';
import PlatformWindowContainer from './containers/PlatformWindowContainer';
import LaunchPage from './containers/LaunchPage';
@@ -15,123 +15,40 @@ import SupportPage from './containers/SupportPage';
import SelectLocationPage from './containers/SelectLocationPage';
import { getTransitionProps } from './transitions';
-import type { ReduxGetState } from './redux/store';
import type App from './app';
-
export type SharedRouteProps = {
app: App,
};
-export default function makeRoutes(
- getState: ReduxGetState,
- componentProps: SharedRouteProps,
-): React.Element<*> {
- // Merge props and render component
- const renderMergedProps = (
- ComponentClass: React.ComponentType<*>,
- ...rest: Array<Object>
- ): React.Element<*> => {
- const finalProps = Object.assign({}, componentProps, ...rest);
- return <ComponentClass {...finalProps} />;
- };
-
- // Renders public route
- // example: <PublicRoute path="/" component={ MyComponent } />
- const PublicRoute = ({ component, ...otherProps }) => {
- return (
- <Route
- {...otherProps}
- render={(routeProps) => {
- return renderMergedProps(component, routeProps, otherProps);
- }}
- />
- );
- };
-
- // Renders protected route that requires authentication, otherwise redirects to /
- // example: <PrivateRoute path="/protected" component={ MyComponent } />
- const PrivateRoute = ({ component, ...otherProps }) => {
- return (
- <Route
- {...otherProps}
- render={(routeProps) => {
- const { account } = getState();
- const isLoggedIn = account.status === 'ok';
-
- if (isLoggedIn) {
- return renderMergedProps(component, routeProps, otherProps);
- } else {
- return <Redirect to={'/login'} />;
- }
- }}
- />
- );
- };
-
- // Renders login route that is only available to non-authenticated
- // users. Otherwise this route redirects user to /connect.
- // example: <LoginRoute path="/login" component={ MyComponent } />
- const LoginRoute = ({ component, ...otherProps }) => {
- return (
- <Route
- {...otherProps}
- render={(routeProps) => {
- const { account } = getState();
- const isLoggedIn = account.status === 'ok';
-
- if (isLoggedIn) {
- return <Redirect to={'/connect'} />;
- } else {
- return renderMergedProps(component, routeProps, otherProps);
- }
- }}
- />
- );
- };
-
- // Renders launch route that is only available when daemon is not connected.
- // Otherwise this route redirects user to /login.
- // example: <LaunchRoute path="/" component={ MyComponent } />
- const LaunchRoute = ({ component, ...otherProps }) => {
- return (
- <Route
- {...otherProps}
- render={(routeProps) => {
- const { daemon } = getState();
- if (daemon.isConnected) {
- return <Redirect to={'/login'} />;
- } else {
- return renderMergedProps(component, routeProps, otherProps);
- }
- }}
- />
- );
- };
+export default function makeRoutes(componentProps: SharedRouteProps) {
+ // Renders a route extended with shared props
+ const CustomRoute = ({ component: ComponentClass, ...routeProps }) => (
+ <Route {...routeProps} render={() => <ComponentClass {...componentProps} />} />
+ );
// store previous route
- let previousRoute: ?string;
+ let sourceRoute: ?string;
return (
<Route
render={({ location }) => {
- const toRoute = location.pathname;
- const fromRoute = previousRoute;
- const transitionProps = getTransitionProps(fromRoute, toRoute);
- previousRoute = toRoute;
+ const destinationRoute = location.pathname;
+ const transitionProps = getTransitionProps(sourceRoute, destinationRoute);
+ sourceRoute = destinationRoute;
return (
<PlatformWindowContainer>
<TransitionContainer {...transitionProps}>
<Switch key={location.key} location={location}>
- <LaunchRoute exact path="/" component={LaunchPage} />
- <LoginRoute exact path="/login" component={LoginPage} />
- <PrivateRoute exact path="/connect" component={ConnectPage} />
- <PublicRoute exact path="/settings" component={SettingsPage} />
- <PrivateRoute exact path="/settings/account" component={AccountPage} />
- <PublicRoute exact path="/settings/preferences" component={PreferencesPage} />
- <PublicRoute exact path="/settings/advanced" component={AdvancedSettingsPage} />
- <PublicRoute exact path="/settings/support" component={SupportPage} />
- <PrivateRoute exact path="/select-location" component={SelectLocationPage} />
+ <CustomRoute exact path="/" component={LaunchPage} />
+ <CustomRoute exact path="/login" component={LoginPage} />
+ <CustomRoute exact path="/connect" component={ConnectPage} />
+ <CustomRoute exact path="/settings" component={SettingsPage} />
+ <CustomRoute exact path="/settings/account" component={AccountPage} />
+ <CustomRoute exact path="/settings/preferences" component={PreferencesPage} />
+ <CustomRoute exact path="/settings/advanced" component={AdvancedSettingsPage} />
+ <CustomRoute exact path="/settings/support" component={SupportPage} />
+ <CustomRoute exact path="/select-location" component={SelectLocationPage} />
</Switch>
</TransitionContainer>
</PlatformWindowContainer>