|
99 | 99 |
|
100 | 100 | [Parameter] public GridImageSize CurrentGridSize { get; set; }
|
101 | 101 |
|
102 |
| - private bool NoResultsFound { get; set; } = true; |
| 102 | + private bool NoResultsFound { get; set; } = false; |
103 | 103 |
|
104 | 104 | protected override void OnInitialized()
|
105 | 105 | {
|
|
244 | 244 | // If we've tried to load data and there isn't any more, show the toast.
|
245 | 245 | toastClass = endOfImages ? "show" : string.Empty;
|
246 | 246 |
|
| 247 | + _ = AddImagesToGrid(response.MoreDataAvailable, cancelTokenSource.Token); |
| 248 | + } |
| 249 | + |
| 250 | + private void ResetSearch() |
| 251 | + { |
247 | 252 | // Cancel the old request, and start a new one
|
248 | 253 | cancelTokenSource.Cancel();
|
249 | 254 | cancelTokenSource.Dispose();
|
250 | 255 | cancelTokenSource = new CancellationTokenSource();
|
251 |
| - |
252 |
| - _ = AddImagesToGrid(response.MoreDataAvailable, cancelTokenSource.Token); |
253 | 256 | }
|
254 | 257 |
|
255 |
| - protected void SearchQueryChanged() |
| 258 | + private void SearchQueryChanged() |
256 | 259 | {
|
| 260 | + // Abort any in-progress search results from being rendered |
| 261 | + ResetSearch(); |
| 262 | + |
257 | 263 | selectionService.ClearSelection();
|
258 | 264 | gridImages.Clear();
|
259 | 265 | endOfImages = false;
|
|
289 | 295 |
|
290 | 296 | foreach( var set in chunks )
|
291 | 297 | {
|
292 |
| - // Another refresh, hot on our heels, is cancelling this one |
293 |
| - if( token.IsCancellationRequested ) |
294 |
| - return; |
295 |
| - |
296 | 298 | StateHasChanged();
|
297 | 299 |
|
298 | 300 | var toAdd = set.ExceptBy(gridImages.Select(x => x.ImageId), x => x).ToList();
|
299 |
| - |
300 | 301 | var images = await imageCache.GetCachedImages(toAdd);
|
301 | 302 |
|
| 303 | + // Check if we had a cancellation request while we pulled back the images. If so, abort |
| 304 | + if( token.IsCancellationRequested ) |
| 305 | + return; |
| 306 | + |
302 | 307 | if(images.Any())
|
303 | 308 | {
|
304 | 309 | gridImages.AddRange(images);
|
|
0 commit comments