@@ -27,6 +27,7 @@ internal sealed partial class WeatherListPage : DynamicListPage, IDisposable
2727 private readonly CancellationTokenSource _cts = new ( ) ;
2828
2929 private IListItem [ ] _items = [ ] ;
30+ private bool _isLoading ;
3031 private string _lastSearchQuery = string . Empty ;
3132 private CancellationTokenSource _searchCts = new ( ) ;
3233
@@ -101,6 +102,12 @@ private async Task LoadWeatherForLocation(GeocodingResult location, Cancellation
101102
102103 if ( weatherData ? . Current == null )
103104 {
105+ lock ( _sync )
106+ {
107+ _isLoading = false ;
108+ }
109+
110+ RaiseItemsChanged ( ) ;
104111 return ;
105112 }
106113
@@ -112,16 +119,24 @@ private async Task LoadWeatherForLocation(GeocodingResult location, Cancellation
112119 lock ( _sync )
113120 {
114121 _items = items . ToArray ( ) ;
122+ _isLoading = false ;
115123 }
116124
117125 RaiseItemsChanged ( ) ;
118126 }
119127 catch ( Exception ex )
120128 {
129+ lock ( _sync )
130+ {
131+ _isLoading = false ;
132+ }
133+
121134 ExtensionHost . LogMessage ( new LogMessage
122135 {
123136 Message = $ "Failed to load weather for location: { ex . Message } ",
124137 } ) ;
138+
139+ RaiseItemsChanged ( ) ;
125140 }
126141 }
127142
@@ -257,6 +272,13 @@ private async Task PerformSearchAsync(string query, CancellationToken ct)
257272 {
258273 try
259274 {
275+ lock ( _sync )
276+ {
277+ _isLoading = true ;
278+ }
279+
280+ RaiseItemsChanged ( ) ;
281+
260282 var locations = await _geocodingService . SearchLocationAsync ( query , ct ) . ConfigureAwait ( false ) ;
261283
262284 // Re-check cancellation after the async call returns so that stale results
@@ -278,6 +300,7 @@ private async Task PerformSearchAsync(string query, CancellationToken ct)
278300 lock ( _sync )
279301 {
280302 _items = [ noResultsItem ] ;
303+ _isLoading = false ;
281304 }
282305
283306 RaiseItemsChanged ( ) ;
@@ -315,6 +338,7 @@ private async Task PerformSearchAsync(string query, CancellationToken ct)
315338 lock ( _sync )
316339 {
317340 _items = items . ToArray ( ) ;
341+ _isLoading = false ;
318342 }
319343
320344 RaiseItemsChanged ( ) ;
@@ -325,10 +349,17 @@ private async Task PerformSearchAsync(string query, CancellationToken ct)
325349 }
326350 catch ( Exception ex )
327351 {
352+ lock ( _sync )
353+ {
354+ _isLoading = false ;
355+ }
356+
328357 ExtensionHost . LogMessage ( new LogMessage
329358 {
330359 Message = $ "Search error: { ex . Message } ",
331360 } ) ;
361+
362+ RaiseItemsChanged ( ) ;
332363 }
333364 }
334365
@@ -354,6 +385,18 @@ public override IListItem[] GetItems()
354385 {
355386 lock ( _sync )
356387 {
388+ if ( _isLoading )
389+ {
390+ return
391+ [
392+ new ListItem ( new NoOpCommand ( ) )
393+ {
394+ Title = Resources . loading_data ,
395+ Icon = Icons . WeatherIcon ,
396+ } ,
397+ ] ;
398+ }
399+
357400 return _items ;
358401 }
359402 }
0 commit comments