From 9656e5ed29bfea519da20a6a32550a6672d5c891 Mon Sep 17 00:00:00 2001 From: Davide Date: Tue, 15 Oct 2024 23:48:27 +0200 Subject: [PATCH] Filter servers with category/country of selected server (#735) And use Task for blocking actions in filters. --- .../xcshareddata/swiftpm/Package.resolved | 2 +- Passepartout/Library/Package.swift | 2 +- .../Views/Provider/VPNFiltersModifier.swift | 2 +- .../AppUI/Views/Provider/VPNFiltersView.swift | 7 ++-- .../Provider/VPNProviderContentModifier.swift | 16 ++++++---- .../Provider/iOS/VPNFiltersModifier+iOS.swift | 32 +++++++++---------- .../iOS/VPNProviderServerView+iOS.swift | 8 +++-- 7 files changed, 36 insertions(+), 33 deletions(-) diff --git a/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index ea59c084..a788458d 100644 --- a/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -41,7 +41,7 @@ "kind" : "remoteSourceControl", "location" : "git@github.com:passepartoutvpn/passepartoutkit-source", "state" : { - "revision" : "c4182832032fab8fef24386d209572a2c288e28e" + "revision" : "5c402931e0628f3280c603cce5c8c3d05b1cfa1f" } }, { diff --git a/Passepartout/Library/Package.swift b/Passepartout/Library/Package.swift index 0eb3f00b..8f50f0d6 100644 --- a/Passepartout/Library/Package.swift +++ b/Passepartout/Library/Package.swift @@ -28,7 +28,7 @@ let package = Package( ], dependencies: [ // .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.9.0"), - .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "c4182832032fab8fef24386d209572a2c288e28e"), + .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "5c402931e0628f3280c603cce5c8c3d05b1cfa1f"), // .package(path: "../../../passepartoutkit-source"), .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"), // .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"), diff --git a/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersModifier.swift b/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersModifier.swift index 16b4c00c..de6d7f7b 100644 --- a/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersModifier.swift +++ b/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersModifier.swift @@ -38,7 +38,7 @@ struct VPNFiltersModifier: ViewModifier where Configuration: Deco contentView(with: content) .onChange(of: manager.parameters.filters) { _ in Task { - await manager.applyFilters() + manager.applyFilters() } } } diff --git a/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersView.swift b/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersView.swift index 46a46421..faaede66 100644 --- a/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersView.swift +++ b/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersView.swift @@ -34,9 +34,6 @@ struct VPNFiltersView: View where Configuration: Decodable { @ObservedObject var manager: VPNProviderManager - @State - private var isRefreshing = false - var body: some View { Form { Section { @@ -96,7 +93,9 @@ private extension VPNFiltersView { var clearFiltersButton: some View { Button("Clear filters", role: .destructive) { - manager.resetFilters() + Task { + manager.resetFilters() + } } } } diff --git a/Passepartout/Library/Sources/AppUI/Views/Provider/VPNProviderContentModifier.swift b/Passepartout/Library/Sources/AppUI/Views/Provider/VPNProviderContentModifier.swift index f429c0f3..84a277eb 100644 --- a/Passepartout/Library/Sources/AppUI/Views/Provider/VPNProviderContentModifier.swift +++ b/Passepartout/Library/Sources/AppUI/Views/Provider/VPNProviderContentModifier.swift @@ -84,18 +84,22 @@ private extension VPNProviderContentModifier { guard let providerId else { return } + let initialEntity = isInitial ? selectedEntity : nil if !isInitial { selectedEntity = nil } - vpnProviderManager.view = manager.vpnView( + let view = manager.vpnView( for: providerId, configurationType: OpenVPN.Configuration.self, - initialParameters: .init(sorting: [ - .localizedCountry, - .area, - .hostname - ]) + initialParameters: .init( + sorting: [ + .localizedCountry, + .area, + .hostname + ] + ) ) + vpnProviderManager.setView(view, filteringWith: initialEntity?.server.provider) } func onSelectServer(server: VPNServer, preset: VPNPreset) { diff --git a/Passepartout/Library/Sources/AppUI/Views/Provider/iOS/VPNFiltersModifier+iOS.swift b/Passepartout/Library/Sources/AppUI/Views/Provider/iOS/VPNFiltersModifier+iOS.swift index 1fb90575..1b3a982a 100644 --- a/Passepartout/Library/Sources/AppUI/Views/Provider/iOS/VPNFiltersModifier+iOS.swift +++ b/Passepartout/Library/Sources/AppUI/Views/Provider/iOS/VPNFiltersModifier+iOS.swift @@ -31,24 +31,22 @@ import SwiftUI extension VPNFiltersModifier { func contentView(with content: Content) -> some View { - List { - content - } - .toolbar { - Button { - isFiltersPresented = true - } label: { - Image(systemName: "line.3.horizontal.decrease") + content + .toolbar { + Button { + isFiltersPresented = true + } label: { + Image(systemName: "line.3.horizontal.decrease") + } + .themeModal(isPresented: $isFiltersPresented) { + NavigationStack { + VPNFiltersView(manager: manager) + .navigationTitle("Filters") + .navigationBarTitleDisplayMode(.inline) + } + .presentationDetents([.medium]) + } } - } - .themeModal(isPresented: $isFiltersPresented) { - NavigationStack { - VPNFiltersView(manager: manager) - .navigationTitle("Filters") - .navigationBarTitleDisplayMode(.inline) - } - .presentationDetents([.medium]) - } } } diff --git a/Passepartout/Library/Sources/AppUI/Views/Provider/iOS/VPNProviderServerView+iOS.swift b/Passepartout/Library/Sources/AppUI/Views/Provider/iOS/VPNProviderServerView+iOS.swift index 3bbfcfe1..c27e94c9 100644 --- a/Passepartout/Library/Sources/AppUI/Views/Provider/iOS/VPNProviderServerView+iOS.swift +++ b/Passepartout/Library/Sources/AppUI/Views/Provider/iOS/VPNProviderServerView+iOS.swift @@ -33,9 +33,11 @@ extension VPNProviderServerView { @ViewBuilder var serversView: some View { - ForEach(manager.filteredServers) { server in - Button("\(server.hostname ?? server.id) \(server.provider.countryCodes)") { - selectServer(server) + List { + ForEach(manager.filteredServers, id: \.id) { server in + Button("\(server.hostname ?? server.id) \(server.provider.countryCodes)") { + selectServer(server) + } } } }