From 88c53bed2e934df905b56c4fc12b5c4dc9b9025f Mon Sep 17 00:00:00 2001 From: Davide Date: Thu, 12 Dec 2024 17:35:26 +0100 Subject: [PATCH] Regroup views/logic of VPNProviderServerView --- .../Views/VPN/VPNProviderServerView.swift | 36 +++++++------- .../iOS/VPNProviderServer+Content+iOS.swift | 48 +++++++++---------- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/Library/Sources/AppUIMain/Views/VPN/VPNProviderServerView.swift b/Library/Sources/AppUIMain/Views/VPN/VPNProviderServerView.swift index 800ddf2a..fdb6b6e2 100644 --- a/Library/Sources/AppUIMain/Views/VPN/VPNProviderServerView.swift +++ b/Library/Sources/AppUIMain/Views/VPN/VPNProviderServerView.swift @@ -147,25 +147,6 @@ private extension VPNProviderServerView { return filters } - func compatiblePresets(with server: VPNServer) -> [VPNPreset] { - vpnManager - .presets - .filter { - if let selectedId = filtersViewModel.filters.presetId { - return $0.presetId == selectedId - } - return true - } - .filter { - if let supportedIds = server.provider.supportedPresetIds { - return supportedIds.contains($0.presetId) - } - return true - } - } -} - -private extension VPNProviderServerView { func loadInitialServers() async { do { let repository = try preferencesManager.preferencesRepository(forProviderWithId: providerId) @@ -200,6 +181,23 @@ private extension VPNProviderServerView { } } + func compatiblePresets(with server: VPNServer) -> [VPNPreset] { + vpnManager + .presets + .filter { + if let selectedId = filtersViewModel.filters.presetId { + return $0.presetId == selectedId + } + return true + } + .filter { + if let supportedIds = server.provider.supportedPresetIds { + return supportedIds.contains($0.presetId) + } + return true + } + } + func onNewFilters(_ filters: VPNFilters) { Task { await reloadServers(filters: filters) diff --git a/Library/Sources/AppUIMain/Views/VPN/iOS/VPNProviderServer+Content+iOS.swift b/Library/Sources/AppUIMain/Views/VPN/iOS/VPNProviderServer+Content+iOS.swift index aa9dfe99..241d4e43 100644 --- a/Library/Sources/AppUIMain/Views/VPN/iOS/VPNProviderServer+Content+iOS.swift +++ b/Library/Sources/AppUIMain/Views/VPN/iOS/VPNProviderServer+Content+iOS.swift @@ -98,30 +98,6 @@ private extension VPNProviderServerView.ContentView { } } - var emptyView: some View { - Text(Strings.Views.Vpn.noServers) - } -} - -private extension VPNProviderServerView.ContentView { - var countryCodes: [String] { - filtersViewModel - .countries - .map(\.code) - } - - func isExpandedCountry(_ code: String) -> Binding { - Binding { - expandedCodes.contains(code) - } set: { - if $0 { - expandedCodes.insert(code) - } else { - expandedCodes.remove(code) - } - } - } - func countryView(for code: String) -> some View { serversByCountryCode[code] .map { servers in @@ -159,6 +135,30 @@ private extension VPNProviderServerView.ContentView { } } + var emptyView: some View { + Text(Strings.Views.Vpn.noServers) + } +} + +private extension VPNProviderServerView.ContentView { + var countryCodes: [String] { + filtersViewModel + .countries + .map(\.code) + } + + func isExpandedCountry(_ code: String) -> Binding { + Binding { + expandedCodes.contains(code) + } set: { + if $0 { + expandedCodes.insert(code) + } else { + expandedCodes.remove(code) + } + } + } + func computeServersByCountry(_ servers: [VPNServer]) { var map: [String: [VPNServer]] = [:] servers.forEach {