summaryrefslogtreecommitdiffhomepage
path: root/gui/src/renderer/containers
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-08-17 07:57:39 +0200
committerOskar Nyberg <oskar@mullvad.net>2021-08-17 09:41:03 +0200
commitccafdf50c837fd1de68ecb26364cb4100ada593e (patch)
tree6311696843a86f9cd619480537ebbf4a74a7c0dc /gui/src/renderer/containers
parent8fd9f53a8c909bd757cc777d4e8d66fe6097a4a8 (diff)
downloadmullvadvpn-ccafdf50c837fd1de68ecb26364cb4100ada593e.tar.xz
mullvadvpn-ccafdf50c837fd1de68ecb26364cb4100ada593e.zip
Add filter box to select location view
Diffstat (limited to 'gui/src/renderer/containers')
-rw-r--r--gui/src/renderer/containers/SelectLocationPage.tsx43
1 files changed, 22 insertions, 21 deletions
diff --git a/gui/src/renderer/containers/SelectLocationPage.tsx b/gui/src/renderer/containers/SelectLocationPage.tsx
index edfac6c415..e930dec0fe 100644
--- a/gui/src/renderer/containers/SelectLocationPage.tsx
+++ b/gui/src/renderer/containers/SelectLocationPage.tsx
@@ -8,7 +8,7 @@ import SelectLocation from '../components/SelectLocation';
import withAppContext, { IAppContext } from '../context';
import { IHistoryProps, withHistory } from '../lib/history';
import { RoutePath } from '../lib/routes';
-import { IRelayLocationRedux, RelaySettingsRedux } from '../redux/settings/reducers';
+import { IRelayLocationRedux } from '../redux/settings/reducers';
import { IReduxState, ReduxDispatch } from '../redux/store';
import userInterfaceActions from '../redux/userinterface/actions';
import { LocationScope } from '../redux/userinterface/reducers';
@@ -33,16 +33,17 @@ const mapStateToProps = (state: IReduxState) => {
? state.userInterface.locationScope
: LocationScope.relay;
+ const relaySettings = state.settings.relaySettings;
+ const providers = 'normal' in relaySettings ? relaySettings.normal.providers : [];
+
return {
selectedExitLocation,
selectedBridgeLocation,
- relayLocations: filterLocationsByProvider(
- state.settings.relayLocations,
- state.settings.relaySettings,
- ),
+ relayLocations: filterLocationsByProvider(state.settings.relayLocations, providers),
bridgeLocations: state.settings.bridgeLocations,
locationScope,
allowBridgeSelection,
+ providers,
};
};
const mapDispatchToProps = (dispatch: ReduxDispatch, props: IHistoryProps & IAppContext) => {
@@ -89,29 +90,29 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IHistoryProps & IApp
log.error(`Failed to set the bridge location to closest to exit: ${e.message}`);
}
},
+ onClearProviders: async () => {
+ await props.app.updateRelaySettings({ normal: { providers: [] } });
+ },
};
};
function filterLocationsByProvider(
locations: IRelayLocationRedux[],
- relaySettings: RelaySettingsRedux,
+ providers: string[],
): IRelayLocationRedux[] {
- const providers =
- 'normal' in relaySettings && relaySettings.normal.providers.length > 0
- ? relaySettings.normal.providers
- : undefined;
-
- return locations
- .map((country) => ({
- ...country,
- cities: country.cities
- .map((city) => ({
- ...city,
- relays: city.relays.filter((relay) => providers?.includes(relay.provider) ?? true),
+ return providers.length === 0
+ ? locations
+ : locations
+ .map((country) => ({
+ ...country,
+ cities: country.cities
+ .map((city) => ({
+ ...city,
+ relays: city.relays.filter((relay) => providers.includes(relay.provider)),
+ }))
+ .filter((city) => city.relays.length > 0),
}))
- .filter((city) => city.relays.length > 0),
- }))
- .filter((country) => country.cities.length > 0);
+ .filter((country) => country.cities.length > 0);
}
export default withAppContext(