Move favorites toggle above servers list on iOS (#769)
Improve access to the most used filter.
This commit is contained in:
parent
5e46eb2fe5
commit
33f17ab496
|
@ -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?) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ extension VPNProviderServerView {
|
|||
|
||||
let vpnManager: VPNProviderManager<Configuration>
|
||||
|
||||
// BEWARE: not observed! use .onReceive() + @State
|
||||
let filtersViewModel: VPNFiltersView.Model
|
||||
|
||||
let apis: [APIMapper]
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue