Files
deepdrft/DeepDrftManager/Components/Pages/Tracks/CmsAllReleasesGrid.razor
T

72 lines
3.0 KiB
Plaintext

@using DeepDrftManager.Services
@using DeepDrftModels.DTOs
@inject ICmsTrackService CmsTrackService
@inject ISnackbar Snackbar
@* The ALL-tab content (Phase 9 §8.B): the cross-medium all-releases grid (CUTS, SESSIONS, MIXES
together) with per-row edit, delete, expand-tracks, and the 8.D Type chip. Self-contained — owns its
own data load so a host (TrackList today, the 8.A tab strip later) renders it with no parameters and
no VM plumbing. Re-loads on first render and re-fetches after a row mutation so the list stays in
sync with the catalogue. *@
<CmsAlbumBrowser @ref="_albumBrowser"
Releases="_releases"
IsLoading="_loading"
OnReleasesChanged="OnGridReleasesChanged"
OnWaveformGenerated="OnWaveformGenerated" />
@code {
// Fires after a row mutation (delete) so a host can invalidate sibling caches derived from the same
// catalogue — e.g. TrackList's genre cache. The grid refreshes its own list regardless; this is a
// notification, not the data source. Optional: an embed that has no sibling state leaves it unset.
[Parameter] public EventCallback OnReleasesChanged { get; set; }
/// <summary>
/// Forwarded from the inner <see cref="CmsAlbumBrowser"/>: fires after any per-row waveform
/// generate succeeds so the parent page can refresh its catalogue-wide missing-count badges.
/// </summary>
[Parameter] public EventCallback OnWaveformGenerated { get; set; }
private CmsAlbumBrowser? _albumBrowser;
private IReadOnlyList<ReleaseDto> _releases = Array.Empty<ReleaseDto>();
private bool _loading = true;
/// <summary>
/// Clears the inner grid's cached per-track waveform status so the next row expand re-fetches.
/// Called by the parent page after a catalogue-wide bulk run.
/// </summary>
public Task InvalidateWaveformStatusAsync() =>
_albumBrowser?.InvalidateWaveformStatusAsync() ?? Task.CompletedTask;
protected override Task OnInitializedAsync() => ReloadAsync();
private async Task OnGridReleasesChanged()
{
await ReloadAsync();
await OnReleasesChanged.InvokeAsync();
}
// Single load path: the initial fetch and the post-mutation refresh both run through here. After a
// delete CmsAlbumBrowser has already dropped the row from its own projection, so this re-fetch
// reconciles the authoritative list (track counts, orphaned-release cleanup) without a stale cache.
private async Task ReloadAsync()
{
_loading = true;
StateHasChanged();
var result = await CmsTrackService.GetReleasesAsync();
if (result.Success && result.Value is not null)
{
_releases = result.Value;
}
else
{
_releases = Array.Empty<ReleaseDto>();
var error = result.Messages.FirstOrDefault()?.Message ?? "Unknown error";
Snackbar.Add($"Failed to load releases: {error}", Severity.Error);
}
_loading = false;
StateHasChanged();
}
}