diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2022-07-20 13:51:08 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-07-20 13:51:08 +0200 |
| commit | 678733d46c6ebcee7ce1df376fb1e2e9c4238c07 (patch) | |
| tree | 2e056dfc97036ecc4800b15d8c434517f3b7c93e /gui/src/renderer/containers | |
| parent | 7880feb099f6ed4855989ad293bbd3f7cd3e23c0 (diff) | |
| parent | 8d0d1e3f9ef8398b9cab7861a3a32d6fc4249f8f (diff) | |
| download | mullvadvpn-678733d46c6ebcee7ce1df376fb1e2e9c4238c07.tar.xz mullvadvpn-678733d46c6ebcee7ce1df376fb1e2e9c4238c07.zip | |
Merge branch 'filter-filters'
Diffstat (limited to 'gui/src/renderer/containers')
| -rw-r--r-- | gui/src/renderer/containers/SelectLocationPage.tsx | 59 |
1 files changed, 1 insertions, 58 deletions
diff --git a/gui/src/renderer/containers/SelectLocationPage.tsx b/gui/src/renderer/containers/SelectLocationPage.tsx index 8d928421f4..3ca4ca94ac 100644 --- a/gui/src/renderer/containers/SelectLocationPage.tsx +++ b/gui/src/renderer/containers/SelectLocationPage.tsx @@ -7,9 +7,9 @@ import RelaySettingsBuilder from '../../shared/relay-settings-builder'; import SelectLocation from '../components/SelectLocation'; import withAppContext, { IAppContext } from '../context'; import { createWireguardRelayUpdater } from '../lib/constraint-updater'; +import filterLocations from '../lib/filter-locations'; import { IHistoryProps, withHistory } from '../lib/history'; import { RoutePath } from '../lib/routes'; -import { IRelayLocationRedux } from '../redux/settings/reducers'; import { IReduxState, ReduxDispatch } from '../redux/store'; const mapStateToProps = (state: IReduxState, props: IHistoryProps & IAppContext) => { @@ -126,63 +126,6 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp }; }; -function filterLocations( - locations: IRelayLocationRedux[], - providers: string[], - ownership: Ownership, -): IRelayLocationRedux[] { - const locationsFilteredByOwnership = filterLocationsByOwnership(locations, ownership); - const locationsFilteredByProvider = filterLocationsByProvider( - locationsFilteredByOwnership, - providers, - ); - - return locationsFilteredByProvider; -} - -function filterLocationsByOwnership( - locations: IRelayLocationRedux[], - ownership: Ownership, -): IRelayLocationRedux[] { - if (ownership === Ownership.any) { - return locations; - } - - const expectOwned = ownership === Ownership.mullvadOwned; - return locations - .map((country) => ({ - ...country, - cities: country.cities - .map((city) => ({ - ...city, - relays: city.relays.filter((relay) => relay.owned === expectOwned), - })) - .filter((city) => city.relays.length > 0), - })) - .filter((country) => country.cities.length > 0); -} - -function filterLocationsByProvider( - locations: IRelayLocationRedux[], - providers: string[], -): IRelayLocationRedux[] { - if (providers.length === 0) { - return locations; - } - - return 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((country) => country.cities.length > 0); -} - export default withAppContext( withHistory(connect(mapStateToProps, mapDispatchToProps)(SelectLocation)), ); |
