Regroup views/logic of VPNProviderServerView

This commit is contained in:
Davide 2024-12-12 17:35:26 +01:00
parent 2075f109f2
commit 88c53bed2e
No known key found for this signature in database
GPG Key ID: A48836171C759F5E
2 changed files with 41 additions and 43 deletions

View File

@ -147,25 +147,6 @@ private extension VPNProviderServerView {
return filters
}
func compatiblePresets(with server: VPNServer) -> [VPNPreset<Configuration>] {
vpnManager
.presets
.filter {
if let selectedId = filtersViewModel.filters.presetId {
return $0.presetId == selectedId
}
return true
}
.filter {
if let supportedIds = server.provider.supportedPresetIds {
return supportedIds.contains($0.presetId)
}
return true
}
}
}
private extension VPNProviderServerView {
func loadInitialServers() async {
do {
let repository = try preferencesManager.preferencesRepository(forProviderWithId: providerId)
@ -200,6 +181,23 @@ private extension VPNProviderServerView {
}
}
func compatiblePresets(with server: VPNServer) -> [VPNPreset<Configuration>] {
vpnManager
.presets
.filter {
if let selectedId = filtersViewModel.filters.presetId {
return $0.presetId == selectedId
}
return true
}
.filter {
if let supportedIds = server.provider.supportedPresetIds {
return supportedIds.contains($0.presetId)
}
return true
}
}
func onNewFilters(_ filters: VPNFilters) {
Task {
await reloadServers(filters: filters)

View File

@ -98,30 +98,6 @@ private extension VPNProviderServerView.ContentView {
}
}
var emptyView: some View {
Text(Strings.Views.Vpn.noServers)
}
}
private extension VPNProviderServerView.ContentView {
var countryCodes: [String] {
filtersViewModel
.countries
.map(\.code)
}
func isExpandedCountry(_ code: String) -> Binding<Bool> {
Binding {
expandedCodes.contains(code)
} set: {
if $0 {
expandedCodes.insert(code)
} else {
expandedCodes.remove(code)
}
}
}
func countryView(for code: String) -> some View {
serversByCountryCode[code]
.map { servers in
@ -159,6 +135,30 @@ private extension VPNProviderServerView.ContentView {
}
}
var emptyView: some View {
Text(Strings.Views.Vpn.noServers)
}
}
private extension VPNProviderServerView.ContentView {
var countryCodes: [String] {
filtersViewModel
.countries
.map(\.code)
}
func isExpandedCountry(_ code: String) -> Binding<Bool> {
Binding {
expandedCodes.contains(code)
} set: {
if $0 {
expandedCodes.insert(code)
} else {
expandedCodes.remove(code)
}
}
}
func computeServersByCountry(_ servers: [VPNServer]) {
var map: [String: [VPNServer]] = [:]
servers.forEach {