From e2d9ab3c4e004255efc46c20df4fcbfab5d7c269 Mon Sep 17 00:00:00 2001 From: Jon Petersson Date: Mon, 29 Apr 2024 14:49:37 +0200 Subject: [PATCH] Show custom lists even if no filter constraints match --- .../SelectLocation/CustomListLocationNodeBuilder.swift | 6 ++++-- .../SelectLocation/CustomListsDataSource.swift | 6 +++--- .../SelectLocation/LocationDataSource.swift | 7 ++----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift b/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift index e92a8bda8de7..cc8c3d25bea6 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.lowercased(), 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 6d8f8989fab4..28f40e924af3 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 d6460343e04a..3aa69604e494 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)