2021-06-17 15:32:39 +05:30
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct TrendingCountrySelectionView: View {
|
|
|
|
@State private var query: String = ""
|
2021-06-28 16:13:07 +05:30
|
|
|
|
|
|
|
@ObservedObject private var store = Store<[Country]>()
|
2021-06-17 15:32:39 +05:30
|
|
|
@Binding var selectedCountry: Country
|
|
|
|
|
2021-06-27 04:59:55 +05:30
|
|
|
@Environment(\.dismiss) private var dismiss
|
2021-06-17 15:32:39 +05:30
|
|
|
|
2021-06-27 04:59:55 +05:30
|
|
|
var body: some View {
|
|
|
|
ScrollView(.vertical) {
|
2021-06-28 16:13:07 +05:30
|
|
|
ForEach(store.collection) { country in
|
2021-06-27 04:59:55 +05:30
|
|
|
Button(country.name) {
|
|
|
|
selectedCountry = country
|
2021-06-28 16:13:07 +05:30
|
|
|
dismiss()
|
2021-06-17 15:32:39 +05:30
|
|
|
}
|
|
|
|
}
|
2021-06-27 04:59:55 +05:30
|
|
|
.frame(width: 800)
|
2021-06-17 15:32:39 +05:30
|
|
|
}
|
2021-06-28 16:13:07 +05:30
|
|
|
.searchable(text: $query, prompt: Text("Country name or two letter code"))
|
|
|
|
.onChange(of: query) { newQuery in
|
|
|
|
store.replace(Country.search(newQuery))
|
|
|
|
}
|
2021-06-27 04:59:55 +05:30
|
|
|
.background(.thinMaterial)
|
2021-06-17 15:32:39 +05:30
|
|
|
}
|
|
|
|
}
|