summaryrefslogtreecommitdiffhomepage
path: root/gui/src/renderer/lib
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-07-22 14:43:17 +0200
committerOskar Nyberg <oskar@mullvad.net>2021-07-22 14:43:17 +0200
commitf8e47dc57b4821e119104ba1c1223e32085d7174 (patch)
tree365c04dad43d9de5b6f669e2d5bbf22e48a8b0b8 /gui/src/renderer/lib
parent43a5f956fbc8fc137367fb6676c7c34d3e8f93cf (diff)
parentbefbb4b3aee6b96eb248cdc883a4f42d3901bacc (diff)
downloadmullvadvpn-f8e47dc57b4821e119104ba1c1223e32085d7174.tar.xz
mullvadvpn-f8e47dc57b4821e119104ba1c1223e32085d7174.zip
Merge branch 'add-routes-enum'
Diffstat (limited to 'gui/src/renderer/lib')
-rw-r--r--gui/src/renderer/lib/history.tsx15
-rw-r--r--gui/src/renderer/lib/routes.ts18
2 files changed, 31 insertions, 2 deletions
diff --git a/gui/src/renderer/lib/history.tsx b/gui/src/renderer/lib/history.tsx
index 13968e29b9..a391e70fee 100644
--- a/gui/src/renderer/lib/history.tsx
+++ b/gui/src/renderer/lib/history.tsx
@@ -1,6 +1,7 @@
-import { Location, Action, LocationDescriptor } from 'history';
+import { Location, Action, LocationDescriptorObject, History as OriginalHistory } from 'history';
import React from 'react';
import { RouteComponentProps, useHistory as useReactRouterHistory, withRouter } from 'react-router';
+import { RoutePath } from './routes';
export interface ITransitionSpecification {
name: string;
@@ -37,6 +38,8 @@ export const transitions: ITransitionMap = {
},
};
+type LocationDescriptor<S> = RoutePath | LocationDescriptorObject<S>;
+
type LocationListener<S = unknown> = (
location: Location<S>,
action: Action,
@@ -53,7 +56,7 @@ export default class History {
private index = 0;
private lastAction: Action = 'POP';
- public constructor(location: string | Location<S>, state?: S) {
+ public constructor(location: LocationDescriptor<S>, state?: S) {
this.entries = [this.createLocation(location, state)];
}
@@ -114,6 +117,14 @@ export default class History {
return nextIndex >= 0 && nextIndex < this.entries.length;
}
+ // This returns this object casted as History from the History module. The difference between this
+ // one and the one in the history module is that this one has stricter types for the paths.
+ // Instead of accepting any string it's limited to the paths we actually support. But this history
+ // implementation would handle any string as expected.
+ public get asHistory(): OriginalHistory {
+ return this as OriginalHistory;
+ }
+
public block(): never {
throw Error('Not implemented');
}
diff --git a/gui/src/renderer/lib/routes.ts b/gui/src/renderer/lib/routes.ts
new file mode 100644
index 0000000000..bf8e6e1f60
--- /dev/null
+++ b/gui/src/renderer/lib/routes.ts
@@ -0,0 +1,18 @@
+export enum RoutePath {
+ launch = '/',
+ login = '/login',
+ main = '/main',
+ redeemVoucher = '/main/voucher/redeem',
+ voucherSuccess = '/main/voucher/success',
+ timeAdded = '/main/time-added',
+ setupFinished = '/main/setup-finished',
+ settings = '/settings',
+ selectLanguage = '/settings/language',
+ accountSettings = '/settings/account',
+ preferences = '/settings/preferences',
+ advancedSettings = '/settings/advanced',
+ wireguardKeys = '/settings/advanced/wireguard-keys',
+ splitTunneling = '/settings/advanced/split-tunneling',
+ support = '/settings/support',
+ selectLocation = '/select-location',
+}