summaryrefslogtreecommitdiffhomepage
path: root/gui/src/renderer/components/select-location
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2023-10-04 11:35:59 +0200
committerOskar Nyberg <oskar@mullvad.net>2023-10-09 10:16:53 +0200
commit469c501f736e98ea6a20f1e76b40550d6ad995cd (patch)
tree88c0fbab003216eff6bcaf2fb87c02d634025558 /gui/src/renderer/components/select-location
parent4e26e4c36345afbca25a1a1e760927cd74d2c1a5 (diff)
downloadmullvadvpn-469c501f736e98ea6a20f1e76b40550d6ad995cd.tar.xz
mullvadvpn-469c501f736e98ea6a20f1e76b40550d6ad995cd.zip
Add custom lists to settings, ipc and rpc calls
Diffstat (limited to 'gui/src/renderer/components/select-location')
-rw-r--r--gui/src/renderer/components/select-location/select-location-helpers.ts42
1 files changed, 21 insertions, 21 deletions
diff --git a/gui/src/renderer/components/select-location/select-location-helpers.ts b/gui/src/renderer/components/select-location/select-location-helpers.ts
index 46225645cc..23d059ac0a 100644
--- a/gui/src/renderer/components/select-location/select-location-helpers.ts
+++ b/gui/src/renderer/components/select-location/select-location-helpers.ts
@@ -5,16 +5,20 @@ import {
compareRelayLocationLoose,
LiftedConstraint,
RelayLocation,
+ RelayLocationCity,
+ RelayLocationCountry,
+ RelayLocationCustomList,
+ RelayLocationRelay,
} from '../../../shared/daemon-rpc-types';
import { messages, relayLocations } from '../../../shared/gettext';
import {
IRelayLocationCityRedux,
- IRelayLocationRedux,
+ IRelayLocationCountryRedux,
IRelayLocationRelayRedux,
NormalBridgeSettingsRedux,
NormalRelaySettingsRedux,
} from '../../redux/settings/reducers';
-import { DisabledReason, LocationType } from './select-location-types';
+import { DisabledReason, LocationSpecification, LocationType } from './select-location-types';
export function isSelected(
relayLocation: RelayLocation,
@@ -58,13 +62,10 @@ export function defaultExpandedLocations(
// Expands a relay location and its parents
function expandRelayLocation(location: RelayLocation): RelayLocation[] {
- if ('city' in location) {
- return [{ country: location.city[0] }];
- } else if ('hostname' in location) {
- return [
- { country: location.hostname[0] },
- { city: [location.hostname[0], location.hostname[1]] },
- ];
+ if ('hostname' in location) {
+ return [{ country: location.country }, { country: location.country, city: location.city }];
+ } else if ('city' in location) {
+ return [{ country: location.country }];
} else {
return [];
}
@@ -104,15 +105,12 @@ export function formatRowName(
export function isRelayDisabled(
relay: IRelayLocationRelayRedux,
- location: [string, string, string],
+ location: RelayLocationRelay,
disabledLocation?: { location: RelayLocation; reason: DisabledReason },
): DisabledReason | undefined {
if (!relay.active) {
return DisabledReason.inactive;
- } else if (
- disabledLocation &&
- compareRelayLocation({ hostname: location }, disabledLocation.location)
- ) {
+ } else if (disabledLocation && compareRelayLocation(location, disabledLocation.location)) {
return disabledLocation.reason;
} else {
return undefined;
@@ -121,11 +119,11 @@ export function isRelayDisabled(
export function isCityDisabled(
city: IRelayLocationCityRedux,
- location: [string, string],
+ location: RelayLocationCity,
disabledLocation?: { location: RelayLocation; reason: DisabledReason },
): DisabledReason | undefined {
const relaysDisabled = city.relays.map((relay) =>
- isRelayDisabled(relay, [...location, relay.hostname]),
+ isRelayDisabled(relay, { ...location, hostname: relay.hostname }),
);
if (relaysDisabled.every((status) => status === DisabledReason.inactive)) {
return DisabledReason.inactive;
@@ -144,7 +142,7 @@ export function isCityDisabled(
if (
disabledLocation &&
- compareRelayLocation({ city: location }, disabledLocation.location) &&
+ compareRelayLocation(location, disabledLocation.location) &&
city.relays.filter((relay) => relay.active).length <= 1
) {
return disabledLocation.reason;
@@ -154,11 +152,13 @@ export function isCityDisabled(
}
export function isCountryDisabled(
- country: IRelayLocationRedux,
- location: string,
+ country: IRelayLocationCountryRedux,
+ location: RelayLocationCountry,
disabledLocation?: { location: RelayLocation; reason: DisabledReason },
): DisabledReason | undefined {
- const citiesDisabled = country.cities.map((city) => isCityDisabled(city, [location, city.code]));
+ const citiesDisabled = country.cities.map((city) =>
+ isCityDisabled(city, { ...location, city: city.code }),
+ );
if (citiesDisabled.every((status) => status === DisabledReason.inactive)) {
return DisabledReason.inactive;
}
@@ -175,7 +175,7 @@ export function isCountryDisabled(
if (
disabledLocation &&
- compareRelayLocation({ country: location }, disabledLocation.location) &&
+ compareRelayLocation(location, disabledLocation.location) &&
country.cities.flatMap((city) => city.relays).filter((relay) => relay.active).length <= 1
) {
return disabledLocation.reason;