summaryrefslogtreecommitdiffhomepage
path: root/gui/src
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-06-29 14:50:49 +0200
committerOskar Nyberg <oskar@mullvad.net>2021-07-01 11:37:48 +0200
commitd39d40b4edab918eb4be46e6154c4864f70aee5d (patch)
tree0ee64e1267784bf90ef7702ae0262350c130c3d7 /gui/src
parentd3636bb84afea9e7a9b786bf9ad4fd26951950a8 (diff)
downloadmullvadvpn-d39d40b4edab918eb4be46e6154c4864f70aee5d.tar.xz
mullvadvpn-d39d40b4edab918eb4be46e6154c4864f70aee5d.zip
Adjust routes.tsx to the changes in history.tsx
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/renderer/routes.tsx41
1 files changed, 17 insertions, 24 deletions
diff --git a/gui/src/renderer/routes.tsx b/gui/src/renderer/routes.tsx
index fe49469092..68605821d4 100644
--- a/gui/src/renderer/routes.tsx
+++ b/gui/src/renderer/routes.tsx
@@ -1,6 +1,6 @@
import { Action } from 'history';
import * as React from 'react';
-import { Route, RouteComponentProps, Switch, withRouter } from 'react-router';
+import { Route, Switch } from 'react-router';
import Launch from './components/Launch';
import KeyboardNavigation from './components/KeyboardNavigation';
import MainView from './components/MainView';
@@ -17,8 +17,7 @@ import SelectLocationPage from './containers/SelectLocationPage';
import SettingsPage from './containers/SettingsPage';
import SupportPage from './containers/SupportPage';
import WireguardKeysPage from './containers/WireguardKeysPage';
-import History from './lib/history';
-import { getTransitionProps } from './transitions';
+import { IHistoryProps, ITransitionSpecification, transitions, withHistory } from './lib/history';
import {
SetupFinished,
TimeAdded,
@@ -27,36 +26,35 @@ import {
} from './components/ExpiredAccountAddTime';
interface IAppRoutesState {
- previousLocation?: RouteComponentProps['location'];
- currentLocation: RouteComponentProps['location'];
+ currentLocation: IHistoryProps['history']['location'];
+ transition: ITransitionSpecification;
action?: Action;
}
-class AppRoutes extends React.Component<RouteComponentProps, IAppRoutesState> {
+class AppRoutes extends React.Component<IHistoryProps, IAppRoutesState> {
private unobserveHistory?: () => void;
private focusRef = React.createRef<IFocusHandle>();
- constructor(props: RouteComponentProps) {
+ constructor(props: IHistoryProps) {
super(props);
this.state = {
- currentLocation: props.location,
+ currentLocation: props.history.location,
+ transition: transitions.none,
};
}
public componentDidMount() {
// React throttles updates, so it's impossible to capture the intermediate navigation without
// listening to the history directly.
- this.unobserveHistory = (this.props.history as History).listen(
- (location, action, affectedEntries) => {
- this.setState({
- previousLocation: affectedEntries[0],
- currentLocation: location,
- action,
- });
- },
- );
+ this.unobserveHistory = this.props.history.listen((location, action, transition) => {
+ this.setState({
+ currentLocation: location,
+ transition,
+ action,
+ });
+ });
}
public componentWillUnmount() {
@@ -67,17 +65,12 @@ class AppRoutes extends React.Component<RouteComponentProps, IAppRoutesState> {
public render() {
const location = this.state.currentLocation;
- const transitionProps = getTransitionProps(
- this.state.previousLocation ? this.state.previousLocation.pathname : null,
- location.pathname,
- this.state.action,
- );
return (
<PlatformWindowContainer>
<KeyboardNavigation>
<Focus ref={this.focusRef}>
- <TransitionContainer onTransitionEnd={this.onNavigation} {...transitionProps}>
+ <TransitionContainer onTransitionEnd={this.onNavigation} {...this.state.transition}>
<TransitionView viewId={location.key || ''}>
<Switch key={location.key} location={location}>
<Route exact={true} path="/" component={Launch} />
@@ -122,6 +115,6 @@ class AppRoutes extends React.Component<RouteComponentProps, IAppRoutesState> {
};
}
-const AppRoutesWithRouter = withRouter(AppRoutes);
+const AppRoutesWithRouter = withHistory(AppRoutes);
export default AppRoutesWithRouter;