using Elternbeirat.Contracts; using Elternbeirat.PocketBase; using Microsoft.AspNetCore.Components; namespace Elternbeirat.Web.Features.Faqs; public partial class FaqList { [LoggerMessage(Level = LogLevel.Warning, Message = "Could not load FAQs from PocketBase.")] private static partial void LogLoadFailed(ILogger logger, Exception exception); // German heading per topic. Unknown topics fall back to the raw key so a new // topic in PocketBase still shows up rather than being silently dropped. private static readonly Dictionary TopicLabels = new(StringComparer.Ordinal) { ["mensa"] = "Mensa und Mittagessen", ["schliessfach"] = "Schließfächer", ["elterneuro"] = "Eltern-Euro", ["elternarbeit"] = "Elternarbeit und Mitmachen", }; [Inject] private PocketBaseClient PocketBase { get; set; } = default!; [Inject] private ILogger Logger { get; set; } = default!; private IReadOnlyList> _groups = []; protected override async Task OnInitializedAsync() { try { var faqs = await PocketBase.GetFaqsAsync(); _groups = [.. faqs.GroupBy(faq => faq.Topic)]; } catch (HttpRequestException ex) { // Source unreachable -> show an empty page instead of a 500. The page // stays up; the "keine Fragen" note is rendered. LogLoadFailed(Logger, ex); } } private static string TopicLabel(string topic) => TopicLabels.TryGetValue(topic, out var label) ? label : topic; }