diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-11-12 15:30:44 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-03-14 13:58:44 +0100 |
| commit | 61cacab42463bd0913905c31e5da4a69a4c359c7 (patch) | |
| tree | 905afb559a2c0bfd557a4ea1f4bfdc6099b91e41 /gui/src | |
| parent | 940e39e38b942c04484acc2906f5a3bf77fe4897 (diff) | |
| download | mullvadvpn-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.tsx | 16 | ||||
| -rw-r--r-- | gui/src/renderer/lib/routes.ts | 11 |
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], |
