@page "/catalogue" @using DeepDrftManager.Services @using DeepDrftModels.Enums @attribute [Authorize] @layout Layout.CmsLayout @inject NavigationManager Nav @inject ICmsReleaseService CmsReleaseService @inject ILogger Logger DeepDrft CMS Catalogue @foreach (var card in Cards) { @SummaryCard(card) } @code { // One card per release medium. Each deep-links to /releases with the medium tab pre-selected via the // same ?medium= convention the Add Track buttons use. The count is that medium's release total. private sealed record MediumCard(ReleaseMedium Medium, string Label, string Icon, Color Color); private static readonly IReadOnlyList Cards = new[] { new MediumCard(ReleaseMedium.Cut, "CUTS", Icons.Material.Filled.Album, Color.Primary), new MediumCard(ReleaseMedium.Session, "SESSIONS", Icons.Material.Filled.Mic, Color.Secondary), new MediumCard(ReleaseMedium.Mix, "MIXES", Icons.Material.Filled.GraphicEq, Color.Tertiary), }; // Medium → release count (null while loading or on failure). Each medium's count is one cheap paged // read (pageSize 1) for its TotalCount, run concurrently. private readonly Dictionary _counts = new(); private readonly HashSet _loading = Cards.Select(c => c.Medium).ToHashSet(); protected override async Task OnInitializedAsync() { // Each loader calls StateHasChanged in its finally block so its card updates as soon as its own // fetch returns, rather than blocking on the slowest of the three. await Task.WhenAll(Cards.Select(c => LoadCountAsync(c.Medium))); } private async Task LoadCountAsync(ReleaseMedium medium) { try { // pageSize 1 — we only need TotalCount, not the rows. Sort column is required by the API but // immaterial to the count. var result = await CmsReleaseService.GetPagedAsync( medium, page: 1, pageSize: 1, sortColumn: "Title", sortDescending: false); _counts[medium] = result.Success && result.Value is not null ? result.Value.TotalCount : null; if (!result.Success) { Logger.LogWarning("Dashboard {Medium} count failed: {Error}", medium, result.Messages.FirstOrDefault()?.Message ?? "Unknown error"); } } finally { _loading.Remove(medium); StateHasChanged(); } } private RenderFragment SummaryCard(MediumCard card) => __builder => { var loading = _loading.Contains(card.Medium); var count = _counts.GetValueOrDefault(card.Medium); @if (loading) { } else { @(count?.ToString() ?? "—") } @card.Label View }; // Deep-link to the Releases page with this medium's tab pre-selected. Mirrors the ?medium= seed the // Add Track buttons use; the Releases page reads it to set the active tab. private static string ReleasesHref(ReleaseMedium medium) => $"/releases?medium={medium.ToString().ToLowerInvariant()}"; }