mirror of
https://github.com/passepartoutvpn/passepartout-apple.git
synced 2025-01-31 04:52:05 +00:00
Improve provider servers responsiveness on iOS (#927)
Pre-compute servers by country code. Fixes #898
This commit is contained in:
parent
9c93158a3d
commit
7e49493d75
@ -112,6 +112,9 @@ extension VPNProviderServerView {
|
||||
|
||||
let onSelect: (VPNServer) -> Void
|
||||
|
||||
@State
|
||||
private var serversByCountryCode: [String: [VPNServer]] = [:]
|
||||
|
||||
@State
|
||||
private var expandedCodes: Set<String> = []
|
||||
|
||||
@ -119,6 +122,7 @@ extension VPNProviderServerView {
|
||||
debugChanges()
|
||||
return listView
|
||||
.themeAnimation(on: isFiltering, category: .providers)
|
||||
.onChange(of: servers, perform: computeServersByCountry)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -176,16 +180,8 @@ private extension VPNProviderServerView.ServersSubview {
|
||||
}
|
||||
}
|
||||
|
||||
func countryServers(for code: String) -> [VPNServer]? {
|
||||
servers
|
||||
.filter {
|
||||
$0.provider.countryCode == code
|
||||
}
|
||||
.nilIfEmpty
|
||||
}
|
||||
|
||||
func countryView(for code: String) -> some View {
|
||||
countryServers(for: code)
|
||||
serversByCountryCode[code]
|
||||
.map { servers in
|
||||
DisclosureGroup(isExpanded: isExpandedCountry(code)) {
|
||||
ForEach(servers, id: \.id, content: serverView)
|
||||
@ -219,6 +215,17 @@ private extension VPNProviderServerView.ServersSubview {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func computeServersByCountry(_ servers: [VPNServer]) {
|
||||
var map: [String: [VPNServer]] = [:]
|
||||
servers.forEach {
|
||||
let code = $0.provider.countryCode
|
||||
var list = map[code] ?? []
|
||||
list.append($0)
|
||||
map[code] = list
|
||||
}
|
||||
serversByCountryCode = map
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Preview
|
||||
|
Loading…
Reference in New Issue
Block a user