Fix Pool.secondaryId and use it for sorting
Account for extraCountries.
This commit is contained in:
parent
d9a0ebd923
commit
a12cecb647
|
@ -132,7 +132,7 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate
|
|||
cell.rightText = pool.area?.uppercased()
|
||||
cell.accessoryType = .detailDisclosureButton // no checkmark!
|
||||
} else {
|
||||
cell.rightText = pool.areaId?.uppercased()
|
||||
cell.rightText = pool.secondaryId
|
||||
}
|
||||
cell.isTappable = true
|
||||
return cell
|
||||
|
@ -154,17 +154,9 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate
|
|||
}
|
||||
let vc = OptionViewController<Pool>()
|
||||
vc.title = group.localizedCountry
|
||||
vc.options = group.pools.sorted {
|
||||
guard let lnum = $0.num else {
|
||||
return true
|
||||
}
|
||||
guard let rnum = $1.num else {
|
||||
return false
|
||||
}
|
||||
return lnum < rnum
|
||||
}
|
||||
vc.options = group.pools.sorted { $0.secondaryId < $1.secondaryId }
|
||||
vc.selectedOption = currentPool
|
||||
vc.descriptionBlock = { $0.areaId ?? "" } // XXX: fail gracefully
|
||||
vc.descriptionBlock = { $0.secondaryId }
|
||||
vc.selectionBlock = {
|
||||
self.currentPool = $0
|
||||
self.delegate?.providerPoolController(self, didSelectPool: $0)
|
||||
|
|
|
@ -31,6 +31,8 @@ public struct Pool: Codable, Hashable {
|
|||
case id
|
||||
|
||||
case country
|
||||
|
||||
case extraCountries = "extra_countries"
|
||||
|
||||
case area
|
||||
|
||||
|
@ -48,6 +50,8 @@ public struct Pool: Codable, Hashable {
|
|||
public let id: String
|
||||
|
||||
public let country: String
|
||||
|
||||
public let extraCountries: [String]?
|
||||
|
||||
public let area: String?
|
||||
|
||||
|
@ -95,31 +99,20 @@ extension Pool {
|
|||
}
|
||||
|
||||
public var localizedId: String {
|
||||
let countryString = localizedCountry
|
||||
let zone: String
|
||||
if let area = area, let num = num {
|
||||
zone = "\(area) #\(num)"
|
||||
} else if let area = area {
|
||||
zone = area
|
||||
} else if let num = num {
|
||||
zone = "#\(num)"
|
||||
} else {
|
||||
return countryString
|
||||
}
|
||||
return String.init(format: Pool.localizedFormat, countryString, zone.uppercased())
|
||||
return String.init(format: Pool.localizedFormat, localizedCountry, secondaryId)
|
||||
}
|
||||
|
||||
public var areaId: String? {
|
||||
let id: String
|
||||
if let area = area, let num = num {
|
||||
id = "\(area) #\(num)"
|
||||
} else if let area = area {
|
||||
id = area
|
||||
} else if let num = num {
|
||||
id = "#\(num)"
|
||||
} else {
|
||||
return nil
|
||||
public var secondaryId: String {
|
||||
var comps: [String] = []
|
||||
if let extraCountries = extraCountries {
|
||||
comps.append(contentsOf: extraCountries.map { Utils.localizedCountry($0) })
|
||||
}
|
||||
return id.uppercased()
|
||||
if let area = area {
|
||||
comps.append(area.uppercased())
|
||||
}
|
||||
if let num = num {
|
||||
comps.append("#\(num)")
|
||||
}
|
||||
return comps.joined(separator: " ")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue