From 91a3e42533cd922fcf7cfcbfe0ba81e2a674c782 Mon Sep 17 00:00:00 2001 From: Davide Date: Wed, 23 Oct 2024 21:08:28 +0200 Subject: [PATCH] Start entity selector unfiltered Do some renaming too. --- .../AppUI/Views/App/AppInlineCoordinator.swift | 2 +- .../AppUI/Views/App/AppModalCoordinator.swift | 2 +- ...ectorView.swift => ProviderEntitySelector.swift} | 6 +++--- .../Extensions/OpenVPNModule+Extensions.swift | 9 +-------- ...tor.swift => VPNProviderServerCoordinator.swift} | 13 +++++-------- 5 files changed, 11 insertions(+), 21 deletions(-) rename Passepartout/Library/Sources/AppUI/Views/App/{ProviderSelectorView.swift => ProviderEntitySelector.swift} (94%) rename Passepartout/Library/Sources/AppUI/Views/Provider/{VPNProviderEntityCoordinator.swift => VPNProviderServerCoordinator.swift} (88%) diff --git a/Passepartout/Library/Sources/AppUI/Views/App/AppInlineCoordinator.swift b/Passepartout/Library/Sources/AppUI/Views/App/AppInlineCoordinator.swift index 1af6bb76..f13e168b 100644 --- a/Passepartout/Library/Sources/AppUI/Views/App/AppInlineCoordinator.swift +++ b/Passepartout/Library/Sources/AppUI/Views/App/AppInlineCoordinator.swift @@ -143,7 +143,7 @@ private extension AppInlineCoordinator { func modalDestination(for item: ModalRoute?) -> some View { switch item { case .editProviderEntity(let profile, let module, let provider): - ProviderSelectorView( + ProviderEntitySelector( profileManager: profileManager, tunnel: tunnel, profile: profile, diff --git a/Passepartout/Library/Sources/AppUI/Views/App/AppModalCoordinator.swift b/Passepartout/Library/Sources/AppUI/Views/App/AppModalCoordinator.swift index b0b87b08..5dfe2438 100644 --- a/Passepartout/Library/Sources/AppUI/Views/App/AppModalCoordinator.swift +++ b/Passepartout/Library/Sources/AppUI/Views/App/AppModalCoordinator.swift @@ -135,7 +135,7 @@ extension AppModalCoordinator { } case .editProviderEntity(let profile, let module, let provider): - ProviderSelectorView( + ProviderEntitySelector( profileManager: profileManager, tunnel: tunnel, profile: profile, diff --git a/Passepartout/Library/Sources/AppUI/Views/App/ProviderSelectorView.swift b/Passepartout/Library/Sources/AppUI/Views/App/ProviderEntitySelector.swift similarity index 94% rename from Passepartout/Library/Sources/AppUI/Views/App/ProviderSelectorView.swift rename to Passepartout/Library/Sources/AppUI/Views/App/ProviderEntitySelector.swift index 4973e5fe..8a0f857b 100644 --- a/Passepartout/Library/Sources/AppUI/Views/App/ProviderSelectorView.swift +++ b/Passepartout/Library/Sources/AppUI/Views/App/ProviderEntitySelector.swift @@ -1,5 +1,5 @@ // -// ProviderSelectorView.swift +// ProviderEntitySelector.swift // Passepartout // // Created by Davide De Rosa on 10/22/24. @@ -27,7 +27,7 @@ import AppLibrary import PassepartoutKit import SwiftUI -struct ProviderSelectorView: View { +struct ProviderEntitySelector: View { @EnvironmentObject private var profileProcessor: ProfileProcessor @@ -53,7 +53,7 @@ struct ProviderSelectorView: View { } } -private extension ProviderSelectorView { +private extension ProviderEntitySelector { func onSelect(_ entity: any ProviderEntity & Encodable) async throws { pp_log(.app, .info, "Select new provider entity: \(entity)") diff --git a/Passepartout/Library/Sources/AppUI/Views/Modules/Extensions/OpenVPNModule+Extensions.swift b/Passepartout/Library/Sources/AppUI/Views/Modules/Extensions/OpenVPNModule+Extensions.swift index 9f242ea5..953f812d 100644 --- a/Passepartout/Library/Sources/AppUI/Views/Modules/Extensions/OpenVPNModule+Extensions.swift +++ b/Passepartout/Library/Sources/AppUI/Views/Modules/Extensions/OpenVPNModule+Extensions.swift @@ -49,15 +49,8 @@ extension OpenVPNModule: ProviderEntityViewProviding { with provider: ModuleMetadata.Provider, onSelect: @escaping (any ProviderEntity & Encodable) async throws -> Void ) -> some View { - let selectedEntity: VPNEntity? = try? provider - .entity - .map { - try providerEntity(from: $0.data) - } - - return VPNProviderEntityCoordinator( + VPNProviderServerCoordinator( providerId: provider.id, - selectedEntity: selectedEntity, onSelect: onSelect ) } diff --git a/Passepartout/Library/Sources/AppUI/Views/Provider/VPNProviderEntityCoordinator.swift b/Passepartout/Library/Sources/AppUI/Views/Provider/VPNProviderServerCoordinator.swift similarity index 88% rename from Passepartout/Library/Sources/AppUI/Views/Provider/VPNProviderEntityCoordinator.swift rename to Passepartout/Library/Sources/AppUI/Views/Provider/VPNProviderServerCoordinator.swift index 5f713d79..2db55d9c 100644 --- a/Passepartout/Library/Sources/AppUI/Views/Provider/VPNProviderEntityCoordinator.swift +++ b/Passepartout/Library/Sources/AppUI/Views/Provider/VPNProviderServerCoordinator.swift @@ -1,5 +1,5 @@ // -// VPNProviderEntityCoordinator.swift +// VPNProviderServerCoordinator.swift // Passepartout // // Created by Davide De Rosa on 10/16/24. @@ -27,15 +27,13 @@ import PassepartoutKit import SwiftUI import UtilsLibrary -struct VPNProviderEntityCoordinator: View where Configuration: ProviderConfigurationIdentifiable & Codable { +struct VPNProviderServerCoordinator: View where Configuration: ProviderConfigurationIdentifiable & Codable { @Environment(\.dismiss) private var dismiss let providerId: ProviderID - let selectedEntity: VPNEntity? - let onSelect: (VPNEntity) async throws -> Void @StateObject @@ -44,10 +42,9 @@ struct VPNProviderEntityCoordinator: View where Configuration: Pr var body: some View { NavigationStack { VPNProviderServerView( - apis: API.shared, providerId: providerId, configurationType: Configuration.self, - selectedEntity: selectedEntity, + selectedEntity: nil, onSelect: onSelect ) .toolbar { @@ -68,7 +65,7 @@ struct VPNProviderEntityCoordinator: View where Configuration: Pr } } -private extension VPNProviderEntityCoordinator { +private extension VPNProviderServerCoordinator { func onSelect(server: VPNServer, preset: VPNPreset) { Task { do { @@ -76,7 +73,7 @@ private extension VPNProviderEntityCoordinator { try await onSelect(entity) dismiss() } catch { - pp_log(.app, .fault, "Unable to select server \(server.serverId): \(error)") + pp_log(.app, .fault, "Unable to select server \(server.serverId) for provider \(server.provider.id): \(error)") errorHandler.handle(error, title: Strings.Global.servers) } }