Skip to content

Commit 1ecf9f9

Browse files
committed
Show progress view while loading countries and No countries found text when user search doesn't match countries list.
1 parent f7f17e0 commit 1ecf9f9

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

iosApp/iosApp/ContentView.swift

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,43 @@ struct CountryListView: View {
5252
@State var query: String = ""
5353

5454
var body: some View {
55-
NavigationView {
56-
List {
57-
ForEach(viewModel.countryList.filter { query.isEmpty || $0.name.contains(query)}, id: \.self) { country in
58-
NavigationLink(destination: CountryInfoDetailedViewShared(country: country)) {
59-
HStack {
60-
Text(country.name).font(.headline)
55+
NavigationView {
56+
ZStack {
57+
List {
58+
ForEach(viewModel.countryList.filter { query.isEmpty || $0.name.contains(query) }, id: \.self) { country in
59+
NavigationLink(destination: CountryInfoDetailedViewShared(country: country)) {
60+
HStack {
61+
Text(country.name).font(.headline)
62+
}
63+
}
6164
}
6265
}
66+
.searchable(text: $query)
67+
68+
// Conditional display of the ProgressView
69+
if let isLoading = viewModel.isLoadingCountries.value_ as? Bool, isLoading {
70+
ProgressView()
71+
.progressViewStyle(CircularProgressViewStyle())
72+
.scaleEffect(1.5)
73+
.frame(maxWidth: .infinity, maxHeight: .infinity)
74+
} else if viewModel.countryList.filter({ query.isEmpty || $0.name.contains(query) }).isEmpty {
75+
// Conditional display of text when query result is empty from search bar
76+
Text("No Countries Found!")
77+
.font(.headline)
78+
.foregroundColor(.gray)
79+
.frame(maxWidth: .infinity, maxHeight: .infinity)
80+
}
6381
}
64-
}
65-
.searchable(text: $query)
66-
.navigationBarTitleDisplayMode(.inline)
67-
.toolbar {
68-
ToolbarItem(placement: .principal) {
69-
VStack {
70-
Text("ClimateTrace").font(.headline)
82+
.navigationBarTitleDisplayMode(.inline)
83+
.toolbar {
84+
ToolbarItem(placement: .principal) {
85+
VStack {
86+
Text("ClimateTrace").font(.headline)
87+
}
7188
}
7289
}
7390
}
7491
}
75-
}
7692
}
7793

7894

0 commit comments

Comments
 (0)