summaryrefslogtreecommitdiffhomepage
path: root/gui/src
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2024-04-08 08:18:49 +0200
committerOskar Nyberg <oskar@mullvad.net>2024-04-11 17:21:23 +0200
commitabd2912d013df44c6aea983205c4bc173f6f748b (patch)
tree4f69d6b6d5be70941f05e3769644862329ab3092 /gui/src
parentd8ead1aa606fe9fec9cc0875dc86dd2829324971 (diff)
downloadmullvadvpn-abd2912d013df44c6aea983205c4bc173f6f748b.tar.xz
mullvadvpn-abd2912d013df44c6aea983205c4bc173f6f748b.zip
Move location type state to redux
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/renderer/components/select-location/SelectLocationContainer.tsx14
-rw-r--r--gui/src/renderer/redux/userinterface/actions.ts17
-rw-r--r--gui/src/renderer/redux/userinterface/reducers.ts9
3 files changed, 34 insertions, 6 deletions
diff --git a/gui/src/renderer/components/select-location/SelectLocationContainer.tsx b/gui/src/renderer/components/select-location/SelectLocationContainer.tsx
index 5843d5e6f4..1d0e5251f7 100644
--- a/gui/src/renderer/components/select-location/SelectLocationContainer.tsx
+++ b/gui/src/renderer/components/select-location/SelectLocationContainer.tsx
@@ -1,5 +1,8 @@
import React, { useContext, useMemo, useState } from 'react';
+import useActions from '../../lib/actionsHook';
+import { useSelector } from '../../redux/store';
+import userInterface from '../../redux/userinterface/actions';
import { RelayListContextProvider } from './RelayListContext';
import { ScrollPositionContextProvider } from './ScrollPositionContext';
import { LocationType } from './select-location-types';
@@ -20,13 +23,14 @@ export function useSelectLocationContext() {
}
export default function SelectLocationContainer() {
- const [locationType, setLocationType] = useState(LocationType.exit);
+ const locationType = useSelector((state) => state.userInterface.selectLocationView);
+ const { setSelectLocationView } = useActions(userInterface);
const [searchTerm, setSearchTerm] = useState('');
- const value = useMemo(() => ({ locationType, setLocationType, searchTerm, setSearchTerm }), [
- locationType,
- searchTerm,
- ]);
+ const value = useMemo(
+ () => ({ locationType, setLocationType: setSelectLocationView, searchTerm, setSearchTerm }),
+ [locationType, searchTerm],
+ );
return (
<selectLocationContext.Provider value={value}>
diff --git a/gui/src/renderer/redux/userinterface/actions.ts b/gui/src/renderer/redux/userinterface/actions.ts
index b4b5885370..cc43990980 100644
--- a/gui/src/renderer/redux/userinterface/actions.ts
+++ b/gui/src/renderer/redux/userinterface/actions.ts
@@ -1,5 +1,6 @@
import { MacOsScrollbarVisibility } from '../../../shared/ipc-schema';
import { IChangelog } from '../../../shared/ipc-types';
+import { LocationType } from '../../components/select-location/select-location-types';
export interface IUpdateLocaleAction {
type: 'UPDATE_LOCALE';
@@ -50,6 +51,11 @@ export interface ISetIsPerformingPostUpgrade {
isPerformingPostUpgrade: boolean;
}
+export interface ISetSelectLocationView {
+ type: 'SET_SELECT_LOCATION_VIEW';
+ selectLocationView: LocationType;
+}
+
export type UserInterfaceAction =
| IUpdateLocaleAction
| IUpdateWindowArrowPositionAction
@@ -60,7 +66,8 @@ export type UserInterfaceAction =
| ISetDaemonAllowed
| ISetChangelog
| ISetForceShowChanges
- | ISetIsPerformingPostUpgrade;
+ | ISetIsPerformingPostUpgrade
+ | ISetSelectLocationView;
function updateLocale(locale: string): IUpdateLocaleAction {
return {
@@ -133,6 +140,13 @@ function setIsPerformingPostUpgrade(isPerformingPostUpgrade: boolean): ISetIsPer
};
}
+function setSelectLocationView(selectLocationView: LocationType): ISetSelectLocationView {
+ return {
+ type: 'SET_SELECT_LOCATION_VIEW',
+ selectLocationView,
+ };
+}
+
export default {
updateLocale,
updateWindowArrowPosition,
@@ -144,4 +158,5 @@ export default {
setChangelog,
setForceShowChanges,
setIsPerformingPostUpgrade,
+ setSelectLocationView,
};
diff --git a/gui/src/renderer/redux/userinterface/reducers.ts b/gui/src/renderer/redux/userinterface/reducers.ts
index f9ecc6fdad..622b7814aa 100644
--- a/gui/src/renderer/redux/userinterface/reducers.ts
+++ b/gui/src/renderer/redux/userinterface/reducers.ts
@@ -1,5 +1,6 @@
import { MacOsScrollbarVisibility } from '../../../shared/ipc-schema';
import { IChangelog } from '../../../shared/ipc-types';
+import { LocationType } from '../../components/select-location/select-location-types';
import { ReduxAction } from '../store';
export interface IUserInterfaceReduxState {
@@ -13,6 +14,7 @@ export interface IUserInterfaceReduxState {
changelog: IChangelog;
forceShowChanges: boolean;
isPerformingPostUpgrade: boolean;
+ selectLocationView: LocationType;
}
const initialState: IUserInterfaceReduxState = {
@@ -25,6 +27,7 @@ const initialState: IUserInterfaceReduxState = {
changelog: [],
forceShowChanges: false,
isPerformingPostUpgrade: false,
+ selectLocationView: LocationType.exit,
};
export default function (
@@ -71,6 +74,12 @@ export default function (
isPerformingPostUpgrade: action.isPerformingPostUpgrade,
};
+ case 'SET_SELECT_LOCATION_VIEW':
+ return {
+ ...state,
+ selectLocationView: action.selectLocationView,
+ };
+
default:
return state;
}