Move favorites toggle above servers list on iOS (#769)

Improve access to the most used filter.
This commit is contained in:
Davide 2024-10-28 23:00:41 +01:00 committed by GitHub
parent 5e46eb2fe5
commit 33f17ab496
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 21 deletions

View File

@ -54,11 +54,26 @@ extension VPNFiltersView {
let onlyShowsFavoritesDidChange = PassthroughSubject<Bool, Never>() let onlyShowsFavoritesDidChange = PassthroughSubject<Bool, Never>()
private var subscriptions: Set<AnyCancellable>
init() { init() {
options = VPNFilterOptions() options = VPNFilterOptions()
categories = [] categories = []
countries = [] countries = []
presets = [] 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?) { func load(options: VPNFilterOptions, initialFilters: VPNFilters?) {

View File

@ -41,7 +41,6 @@ struct VPNFiltersView: View {
countryPicker countryPicker
presetPicker presetPicker
#if os(iOS) #if os(iOS)
favoritesToggle
clearFiltersButton clearFiltersButton
.frame(maxWidth: .infinity, alignment: .center) .frame(maxWidth: .infinity, alignment: .center)
#else #else
@ -56,12 +55,6 @@ struct VPNFiltersView: View {
.onChange(of: model.filters.categoryName) { _ in .onChange(of: model.filters.categoryName) { _ in
model.filters.countryCode = nil 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 { var clearFiltersButton: some View {
Button(Strings.Providers.clearFilters, role: .destructive) { Button(Strings.Providers.clearFilters, role: .destructive) {
model.filters = VPNFilters() model.filters = VPNFilters()
model.onlyShowsFavorites = false
} }
} }
} }

View File

@ -104,6 +104,7 @@ extension VPNProviderServerView {
let vpnManager: VPNProviderManager<Configuration> let vpnManager: VPNProviderManager<Configuration>
// BEWARE: not observed! use .onReceive() + @State
let filtersViewModel: VPNFiltersView.Model let filtersViewModel: VPNFiltersView.Model
let apis: [APIMapper] let apis: [APIMapper]

View File

@ -109,13 +109,7 @@ extension VPNProviderServerView {
var body: some View { var body: some View {
debugChanges() debugChanges()
return ZStack { return listView
if isFiltering || !servers.isEmpty {
listView
} else {
emptyView
}
}
.themeAnimation(on: isFiltering, category: .providers) .themeAnimation(on: isFiltering, category: .providers)
} }
} }
@ -125,12 +119,19 @@ private extension VPNProviderServerView.ServersSubview {
var listView: some View { var listView: some View {
List { List {
Section { Section {
Toggle(Strings.Providers.onlyFavorites, isOn: $filtersViewModel.onlyShowsFavorites)
}
Section {
if isFiltering || !servers.isEmpty {
if isFiltering { if isFiltering {
ProgressView() ProgressView()
.id(UUID()) .id(UUID())
} else { } else {
ForEach(countryCodes, id: \.self, content: countryView) ForEach(countryCodes, id: \.self, content: countryView)
} }
} else {
emptyView
}
} header: { } header: {
Text(filtersViewModel.filters.categoryName ?? Strings.Providers.Vpn.Category.any) Text(filtersViewModel.filters.categoryName ?? Strings.Providers.Vpn.Category.any)
} }
@ -139,7 +140,6 @@ private extension VPNProviderServerView.ServersSubview {
var emptyView: some View { var emptyView: some View {
Text(Strings.Providers.Vpn.noServers) Text(Strings.Providers.Vpn.noServers)
.themeEmptyMessage()
} }
} }