From 03cb05da7e7b2e26b7ad7a7683af2169c9489efb Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 27 Apr 2022 19:51:46 +0200 Subject: [PATCH] Do not disable providers while updating index --- Passepartout/App/Views/AddProviderView.swift | 24 ++++--------------- .../App/Views/AddProviderViewModel.swift | 21 ++++++++++++++++ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Passepartout/App/Views/AddProviderView.swift b/Passepartout/App/Views/AddProviderView.swift index 23bc8e3a..f29ec13c 100644 --- a/Passepartout/App/Views/AddProviderView.swift +++ b/Passepartout/App/Views/AddProviderView.swift @@ -58,20 +58,6 @@ struct AddProviderView: View { return protos.sorted() } - private func isFetchingProvider(_ name: ProviderName) -> Bool { - if case .provider(name) = viewModel.pendingOperation { - return true - } - return false - } - - private var isUpdatingIndex: Bool { - if case .index = viewModel.pendingOperation { - return true - } - return false - } - var body: some View { ZStack { ForEach(providers, id: \.navigationId, content: hiddenProviderLink) @@ -85,8 +71,7 @@ struct AddProviderView: View { viewModel.updateIndex(providerManager) }.onChange(of: viewModel.errorMessage) { onErrorMessage($0, scrollProxy) - }.disabled(viewModel.pendingOperation != nil) - .themeAnimation(on: providers) + }.themeAnimation(on: providers) } }.toolbar { themeCloseItem(isPresented: bindings.$isPresented) @@ -120,7 +105,7 @@ struct AddProviderView: View { footer: themeErrorMessage(viewModel.errorMessage) ) { ForEach(providers, content: providerRow) - } + }.disabled(viewModel.isFetchingAnyProvider) } private func providerRow(_ metadata: ProviderMetadata) -> some View { @@ -128,7 +113,7 @@ struct AddProviderView: View { presentOrPurchaseProvider(metadata) } label: { Label(metadata.description, image: themeAssetsProviderImage(metadata.name)) - }.withTrailingProgress(when: isFetchingProvider(metadata.name)) + }.withTrailingProgress(when: viewModel.isFetchingProvider(metadata.name)) } private func hiddenProviderLink(_ metadata: ProviderMetadata) -> some View { @@ -144,7 +129,8 @@ struct AddProviderView: View { private var updateListButton: some View { Button(L10n.AddProfile.Provider.Items.updateList) { viewModel.updateIndex(providerManager) - }.withTrailingProgress(when: isUpdatingIndex) + }.withTrailingProgress(when: viewModel.isUpdatingIndex) + .disabled(viewModel.isUpdatingIndex) } // eligibility: select or purchase provider diff --git a/Passepartout/App/Views/AddProviderViewModel.swift b/Passepartout/App/Views/AddProviderViewModel.swift index e222f00c..bc8e4b23 100644 --- a/Passepartout/App/Views/AddProviderViewModel.swift +++ b/Passepartout/App/Views/AddProviderViewModel.swift @@ -34,6 +34,27 @@ extension AddProviderView { case provider(ProviderName) } + var isUpdatingIndex: Bool { + if case .index = pendingOperation { + return true + } + return false + } + + var isFetchingAnyProvider: Bool { + if case .provider = pendingOperation { + return true + } + return false + } + + func isFetchingProvider(_ name: ProviderName) -> Bool { + if case .provider(name) = pendingOperation { + return true + } + return false + } + @Published var selectedVPNProtocol: VPNProtocolType = .openVPN @Published var selectedProvider: ProviderMetadata?