diff --git a/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersView+Model.swift b/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersView+Model.swift index 8623f755..f718ea3d 100644 --- a/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersView+Model.swift +++ b/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersView+Model.swift @@ -54,11 +54,26 @@ extension VPNFiltersView { let onlyShowsFavoritesDidChange = PassthroughSubject() + private var subscriptions: Set + init() { options = VPNFilterOptions() categories = [] countries = [] presets = [] + subscriptions = [] + + $filters + .sink { [weak self] in + self?.filtersDidChange.send($0) + } + .store(in: &subscriptions) + + $onlyShowsFavorites + .sink { [weak self] in + self?.onlyShowsFavoritesDidChange.send($0) + } + .store(in: &subscriptions) } func load(options: VPNFilterOptions, initialFilters: VPNFilters?) { diff --git a/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersView.swift b/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersView.swift index a2933528..2c0a1567 100644 --- a/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersView.swift +++ b/Passepartout/Library/Sources/AppUI/Views/Provider/VPNFiltersView.swift @@ -41,7 +41,6 @@ struct VPNFiltersView: View { countryPicker presetPicker #if os(iOS) - favoritesToggle clearFiltersButton .frame(maxWidth: .infinity, alignment: .center) #else @@ -56,12 +55,6 @@ struct VPNFiltersView: View { .onChange(of: model.filters.categoryName) { _ in model.filters.countryCode = nil } - .onChange(of: model.filters) { - model.filtersDidChange.send($0) - } - .onChange(of: model.onlyShowsFavorites) { - model.onlyShowsFavoritesDidChange.send($0) - } } } @@ -106,7 +99,6 @@ private extension VPNFiltersView { var clearFiltersButton: some View { Button(Strings.Providers.clearFilters, role: .destructive) { model.filters = VPNFilters() - model.onlyShowsFavorites = false } } } diff --git a/Passepartout/Library/Sources/AppUI/Views/Provider/VPNProviderServerView.swift b/Passepartout/Library/Sources/AppUI/Views/Provider/VPNProviderServerView.swift index dd2d1205..3bfe3197 100644 --- a/Passepartout/Library/Sources/AppUI/Views/Provider/VPNProviderServerView.swift +++ b/Passepartout/Library/Sources/AppUI/Views/Provider/VPNProviderServerView.swift @@ -104,6 +104,7 @@ extension VPNProviderServerView { let vpnManager: VPNProviderManager + // BEWARE: not observed! use .onReceive() + @State let filtersViewModel: VPNFiltersView.Model let apis: [APIMapper] 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 204cb81f..30a01d38 100644 --- a/Passepartout/Library/Sources/AppUI/Views/Provider/iOS/VPNProviderServerView+iOS.swift +++ b/Passepartout/Library/Sources/AppUI/Views/Provider/iOS/VPNProviderServerView+iOS.swift @@ -109,14 +109,8 @@ extension VPNProviderServerView { var body: some View { debugChanges() - return ZStack { - if isFiltering || !servers.isEmpty { - listView - } else { - emptyView - } - } - .themeAnimation(on: isFiltering, category: .providers) + return listView + .themeAnimation(on: isFiltering, category: .providers) } } } @@ -125,11 +119,18 @@ private extension VPNProviderServerView.ServersSubview { var listView: some View { List { Section { - if isFiltering { - ProgressView() - .id(UUID()) + Toggle(Strings.Providers.onlyFavorites, isOn: $filtersViewModel.onlyShowsFavorites) + } + Section { + if isFiltering || !servers.isEmpty { + if isFiltering { + ProgressView() + .id(UUID()) + } else { + ForEach(countryCodes, id: \.self, content: countryView) + } } else { - ForEach(countryCodes, id: \.self, content: countryView) + emptyView } } header: { Text(filtersViewModel.filters.categoryName ?? Strings.Providers.Vpn.Category.any) @@ -139,7 +140,6 @@ private extension VPNProviderServerView.ServersSubview { var emptyView: some View { Text(Strings.Providers.Vpn.noServers) - .themeEmptyMessage() } }