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>()
|
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?) {
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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]
|
||||||
|
|
|
@ -109,14 +109,8 @@ extension VPNProviderServerView {
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
debugChanges()
|
debugChanges()
|
||||||
return ZStack {
|
return listView
|
||||||
if isFiltering || !servers.isEmpty {
|
.themeAnimation(on: isFiltering, category: .providers)
|
||||||
listView
|
|
||||||
} else {
|
|
||||||
emptyView
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.themeAnimation(on: isFiltering, category: .providers)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,11 +119,18 @@ private extension VPNProviderServerView.ServersSubview {
|
||||||
var listView: some View {
|
var listView: some View {
|
||||||
List {
|
List {
|
||||||
Section {
|
Section {
|
||||||
if isFiltering {
|
Toggle(Strings.Providers.onlyFavorites, isOn: $filtersViewModel.onlyShowsFavorites)
|
||||||
ProgressView()
|
}
|
||||||
.id(UUID())
|
Section {
|
||||||
|
if isFiltering || !servers.isEmpty {
|
||||||
|
if isFiltering {
|
||||||
|
ProgressView()
|
||||||
|
.id(UUID())
|
||||||
|
} else {
|
||||||
|
ForEach(countryCodes, id: \.self, content: countryView)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ForEach(countryCodes, id: \.self, content: countryView)
|
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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue