|
43 | 43 | </div> |
44 | 44 |
|
45 | 45 | <div class="row mb-3 g-2 mux-filter-row"> |
46 | | - @if (SelectedItems.Count > 0) |
| 46 | + @if (SelectedIds.Count > 0) |
47 | 47 | { |
48 | 48 | <div class="col-auto"> |
49 | 49 | <button @onclick="QueueSelected" class="btn btn-success btn-sm" type="button" |
|
56 | 56 | { |
57 | 57 | <i class="bi bi-plus-circle me-1"></i> |
58 | 58 | } |
59 | | - Queue @SelectedItems.Count to conversion |
| 59 | + Queue @SelectedIds.Count to conversion |
60 | 60 | </button> |
61 | 61 | </div> |
62 | 62 | <div class="col-auto"> |
63 | 63 | <button @onclick="BatchEditSelected" class="btn btn-outline-primary btn-sm" type="button" |
64 | 64 | disabled="@_isQueueing"> |
65 | | - <i class="bi bi-sliders me-1"></i>Edit tracks on @SelectedItems.Count |
| 65 | + <i class="bi bi-sliders me-1"></i>Edit tracks on @SelectedIds.Count |
66 | 66 | </button> |
67 | 67 | </div> |
68 | 68 | } |
|
375 | 375 | private bool _isQueueing; |
376 | 376 | private bool _disposed; |
377 | 377 |
|
378 | | - // Ticks handed back by the batch editor. Consumed by the first list load, |
379 | | - // then dropped so paging and filtering don't keep re-ticking rows. |
380 | | - private HashSet<int>? _restoreIds; |
381 | 378 | private LibraryStatsConfig? _filterOptions; |
382 | 379 | private List<ProfileSummary> _profileSummaries = []; |
383 | 380 |
|
|
416 | 413 | IsAscending = false; |
417 | 414 |
|
418 | 415 | MediaScanner.ScanningStateChanged += OnScanningStateChanged; |
419 | | - _restoreIds = Selections.Get(SelectionToken); |
| 416 | + |
| 417 | + // Ticks handed back by the batch editor; ids, so no page needs to be loaded. |
| 418 | + if (Selections.Get(SelectionToken) is { } restored) |
| 419 | + { |
| 420 | + SelectedIds.UnionWith(restored); |
| 421 | + } |
420 | 422 |
|
421 | 423 | await LoadFilters(); |
422 | 424 |
|
|
425 | 427 | await UpdateList(); |
426 | 428 | } |
427 | 429 |
|
428 | | - // The restore above has run; from here the ticks are the user's business again. |
429 | | - _restoreIds = null; |
430 | | - |
431 | 430 | await using var context = await ContextFactory.CreateDbContextAsync(); |
432 | 431 | _filterOptions = context.Configs.Get<LibraryStatsConfig>(); |
433 | 432 | await LoadProfileSummaries(context); |
|
481 | 480 | TotalItems = result.Total; |
482 | 481 | TotalPages = result.TotalPages; |
483 | 482 | Items = await result.Data.WithTracks().ToListAsync().ConfigureAwait(false); |
484 | | - |
485 | | - // Ticks come back after a trip to the batch editor, which only ever holds ids. |
486 | | - if (_restoreIds != null) |
487 | | - { |
488 | | - foreach (var file in Items.Where(f => _restoreIds.Contains(f.Id))) |
489 | | - { |
490 | | - SelectedItems.Add(file); |
491 | | - } |
492 | | - } |
493 | 483 | } |
494 | 484 |
|
495 | 485 | private IQueryable<MediaFile> ApplyFilters(IQueryable<MediaFile> query) |
|
621 | 611 | StateHasChanged(); |
622 | 612 | try |
623 | 613 | { |
624 | | - await QueueFiles(SelectedItems); |
625 | | - SelectedItems.Clear(); |
| 614 | + // Selected rows may span pages and reloads, so fetch them fresh. |
| 615 | + List<MediaFile> files; |
| 616 | + await using (var context = await ContextFactory.CreateDbContextAsync()) |
| 617 | + { |
| 618 | + files = await context.MediaFiles.WithTracksAndProfile().WhereIdsAsync(SelectedIds); |
| 619 | + } |
| 620 | + |
| 621 | + await QueueFiles(files); |
| 622 | + SelectedIds.Clear(); |
626 | 623 | } |
627 | 624 | finally |
628 | 625 | { |
|
671 | 668 | } |
672 | 669 | } |
673 | 670 |
|
674 | | - private Task BatchEditSelected() |
| 671 | + private void BatchEditSelected() |
675 | 672 | { |
676 | | - // SelectedItems is compared by reference, so paging away and back leaves |
677 | | - // stale duplicates of the same row. Go back to the ids. |
678 | | - var ids = SelectedItems.Select(f => f.Id).Distinct().ToList(); |
679 | | - return BatchEditTracks(q => q.Where(f => ids.Contains(f.Id))); |
| 673 | + // The selection already is the id set the editor needs. |
| 674 | + NavigationManager.NavigateTo($"/library/batch?sel={Selections.Put(SelectedIds)}"); |
680 | 675 | } |
681 | 676 |
|
682 | 677 | private Task BatchEditAllFiltered() |
|
0 commit comments