summaryrefslogtreecommitdiffhomepage
path: root/gui/src
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-11-12 15:30:44 +0100
committerOskar Nyberg <oskar@mullvad.net>2022-03-14 13:58:44 +0100
commit61cacab42463bd0913905c31e5da4a69a4c359c7 (patch)
tree905afb559a2c0bfd557a4ea1f4bfdc6099b91e41 /gui/src
parent940e39e38b942c04484acc2906f5a3bf77fe4897 (diff)
downloadmullvadvpn-61cacab42463bd0913905c31e5da4a69a4c359c7.tar.xz
mullvadvpn-61cacab42463bd0913905c31e5da4a69a4c359c7.zip
Disable dismiss keyboard shortcut for some views
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/renderer/components/KeyboardNavigation.tsx16
-rw-r--r--gui/src/renderer/lib/routes.ts11
2 files changed, 22 insertions, 5 deletions
diff --git a/gui/src/renderer/components/KeyboardNavigation.tsx b/gui/src/renderer/components/KeyboardNavigation.tsx
index 4cfba89452..6b3851a49f 100644
--- a/gui/src/renderer/components/KeyboardNavigation.tsx
+++ b/gui/src/renderer/components/KeyboardNavigation.tsx
@@ -1,5 +1,7 @@
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
+import { useLocation } from 'react-router';
import { useHistory } from '../lib/history';
+import { disableDismissForRoutes, RoutePath } from '../lib/routes';
interface IKeyboardNavigationProps {
children: React.ReactElement;
@@ -9,18 +11,22 @@ interface IKeyboardNavigationProps {
export default function KeyboardNavigation(props: IKeyboardNavigationProps) {
const history = useHistory();
const [backAction, setBackAction] = useState<IBackActionConfiguration>();
+ const location = useLocation();
const handleKeyDown = useCallback(
(event: KeyboardEvent) => {
if (event.key === 'Escape') {
- if (event.shiftKey) {
- history.dismiss(true);
- } else {
- backAction?.action();
+ const path = location.pathname as RoutePath;
+ if (!disableDismissForRoutes.includes(path)) {
+ if (event.shiftKey) {
+ history.dismiss(true);
+ } else {
+ backAction?.action();
+ }
}
}
},
- [history.dismiss, backAction],
+ [history.dismiss, backAction, location.pathname],
);
useEffect(() => {
diff --git a/gui/src/renderer/lib/routes.ts b/gui/src/renderer/lib/routes.ts
index 22b57960d2..d56c36e82a 100644
--- a/gui/src/renderer/lib/routes.ts
+++ b/gui/src/renderer/lib/routes.ts
@@ -24,6 +24,17 @@ export enum RoutePath {
filterByProvider = '/select-location/filter-by-provider',
}
+export const disableDismissForRoutes = [
+ RoutePath.launch,
+ RoutePath.login,
+ RoutePath.tooManyDevices,
+ RoutePath.main,
+ RoutePath.redeemVoucher,
+ RoutePath.voucherSuccess,
+ RoutePath.timeAdded,
+ RoutePath.setupFinished,
+];
+
export function generateRoutePath(
routePath: RoutePath,
parameters: Parameters<typeof generatePath>[1],