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>()
private var subscriptions: Set<AnyCancellable>
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?) {

View File

@ -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
}
}
}

View File

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

View File

@ -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()
}
}