summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJon Petersson <jon.petersson@kvadrat.se>2024-04-29 14:49:37 +0200
committerBug Magnet <marco.nikic@mullvad.net>2024-04-30 11:31:57 +0200
commit80e8ce3239ca88be6901eb1bb8adeec356b0d1f0 (patch)
tree91fcfe78697f7672944541b84d5c1cea37618305
parent31bcf205c645885bf9959665b57f902b54e205ad (diff)
downloadmullvadvpn-80e8ce3239ca88be6901eb1bb8adeec356b0d1f0.tar.xz
mullvadvpn-80e8ce3239ca88be6901eb1bb8adeec356b0d1f0.zip
Show custom lists even if no filter constraints match
-rw-r--r--ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift6
-rw-r--r--ios/MullvadVPN/View controllers/SelectLocation/CustomListsDataSource.swift6
-rw-r--r--ios/MullvadVPN/View controllers/SelectLocation/LocationDataSource.swift7
-rw-r--r--ios/MullvadVPNTests/MullvadVPN/View controllers/SelectLocation/CustomListsDataSourceTests.swift2
4 files changed, 10 insertions, 11 deletions
diff --git a/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift b/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift
index 3f2e22a96f..cef94576c3 100644
--- a/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift
+++ b/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift
@@ -19,7 +19,7 @@ struct CustomListLocationNodeBuilder {
name: customList.name,
code: customList.name,
locations: customList.locations,
- isActive: !customList.locations.isEmpty,
+ isActive: true, // Defaults to true, updated after children have been populated.
customList: customList
)
@@ -47,7 +47,9 @@ struct CustomListLocationNodeBuilder {
}
}
+ listNode.isActive = !listNode.children.isEmpty
listNode.sort()
+
return listNode
}
}
@@ -66,7 +68,7 @@ private extension CustomListLocationNode {
})
.sorted(by: { $0.key < $1.key })
.reduce([]) {
- return $0 + $1.value.sorted(by: { $0.name < $1.name })
+ $0 + $1.value.sorted(by: { $0.name < $1.name })
}
children = sortedChildren
diff --git a/ios/MullvadVPN/View controllers/SelectLocation/CustomListsDataSource.swift b/ios/MullvadVPN/View controllers/SelectLocation/CustomListsDataSource.swift
index 6d8f8989fa..28f40e924a 100644
--- a/ios/MullvadVPN/View controllers/SelectLocation/CustomListsDataSource.swift
+++ b/ios/MullvadVPN/View controllers/SelectLocation/CustomListsDataSource.swift
@@ -25,8 +25,8 @@ class CustomListsDataSource: LocationDataSourceProtocol {
/// Constructs a collection of node trees by copying each matching counterpart
/// from the complete list of nodes created in ``AllLocationDataSource``.
- func reload(allLocationNodes: [LocationNode], isFiltered: Bool) {
- nodes = repository.fetchAll().compactMap { list in
+ func reload(allLocationNodes: [LocationNode]) {
+ nodes = repository.fetchAll().map { list in
let customListWrapper = CustomListLocationNodeBuilder(customList: list, allLocations: allLocationNodes)
let listNode = customListWrapper.customListLocationNode
@@ -38,7 +38,7 @@ class CustomListsDataSource: LocationDataSourceProtocol {
node.code = LocationNode.combineNodeCodes([listNode.code, node.code])
}
- return (isFiltered && listNode.children.isEmpty) ? nil : listNode
+ return listNode
}
}
diff --git a/ios/MullvadVPN/View controllers/SelectLocation/LocationDataSource.swift b/ios/MullvadVPN/View controllers/SelectLocation/LocationDataSource.swift
index d6460343e0..3aa69604e4 100644
--- a/ios/MullvadVPN/View controllers/SelectLocation/LocationDataSource.swift
+++ b/ios/MullvadVPN/View controllers/SelectLocation/LocationDataSource.swift
@@ -18,7 +18,6 @@ final class LocationDataSource:
private var currentSearchString = ""
private var dataSources: [LocationDataSourceProtocol] = []
private var selectedItem: LocationCellViewModel?
- private var hasFilter = false
let tableView: UITableView
let sections: [LocationSection]
@@ -52,8 +51,6 @@ final class LocationDataSource:
}
func setRelays(_ response: REST.ServerRelaysResponse, selectedRelays: UserSelectedRelays?, filter: RelayFilter) {
- hasFilter = filter.providers != .any || filter.ownership != .any
-
let allLocationsDataSource =
dataSources.first(where: { $0 is AllLocationDataSource }) as? AllLocationDataSource
@@ -65,7 +62,7 @@ final class LocationDataSource:
}
allLocationsDataSource?.reload(response, relays: relays)
- customListsDataSource?.reload(allLocationNodes: allLocationsDataSource?.nodes ?? [], isFiltered: hasFilter)
+ customListsDataSource?.reload(allLocationNodes: allLocationsDataSource?.nodes ?? [])
mapSelectedItem(from: selectedRelays)
filterRelays(by: currentSearchString)
@@ -110,7 +107,7 @@ final class LocationDataSource:
.filter { $0.showsChildren }
// Reload data source with (possibly) updated custom lists.
- customListsDataSource.reload(allLocationNodes: allLocationsDataSource.nodes, isFiltered: hasFilter)
+ customListsDataSource.reload(allLocationNodes: allLocationsDataSource.nodes)
// Reapply current selection.
mapSelectedItem(from: selectedRelays)
diff --git a/ios/MullvadVPNTests/MullvadVPN/View controllers/SelectLocation/CustomListsDataSourceTests.swift b/ios/MullvadVPNTests/MullvadVPN/View controllers/SelectLocation/CustomListsDataSourceTests.swift
index 33a97fffcd..1506939178 100644
--- a/ios/MullvadVPNTests/MullvadVPN/View controllers/SelectLocation/CustomListsDataSourceTests.swift
+++ b/ios/MullvadVPNTests/MullvadVPN/View controllers/SelectLocation/CustomListsDataSourceTests.swift
@@ -75,7 +75,7 @@ class CustomListsDataSourceTests: XCTestCase {
extension CustomListsDataSourceTests {
private func setUpDataSource() {
dataSource = CustomListsDataSource(repository: CustomListsRepositoryStub(customLists: customLists))
- dataSource.reload(allLocationNodes: allLocationNodes, isFiltered: false)
+ dataSource.reload(allLocationNodes: allLocationNodes)
}
private func createAllLocationNodes() {