using Elternbeirat.Contracts; using Elternbeirat.PocketBase; using Microsoft.AspNetCore.Components; namespace Elternbeirat.Web.Features.Embeds; public partial class DocumentsEmbed { [LoggerMessage( Level = LogLevel.Warning, Message = "Could not load documents for an embed from PocketBase; the list is omitted.")] private static partial void LogSourceUnavailable( ILogger logger, Exception exception); [Inject] private PocketBaseClient PocketBase { get; set; } = null!; [Inject] private ILogger Logger { get; set; } = null!; [CascadingParameter] private HttpContext? HttpContext { get; set; } private IReadOnlyList> _groups = []; protected override async Task OnInitializedAsync() { try { // GroupBy keeps the groups in the order of their first document, so an // editor orders the groups through the documents' own order field. var documents = await PocketBase.GetDocumentsAsync(HttpContext?.RequestAborted ?? CancellationToken.None); _groups = [.. documents.GroupBy(document => document.Category)]; } catch (PocketBaseUnavailableException exception) { // Only part of the page fails: omit the list, keep the page (and its // 200) intact. LogSourceUnavailable(Logger, exception); } } }