using System.Globalization; using Elternbeirat.Contracts; using Elternbeirat.PocketBase; using Microsoft.AspNetCore.Components; namespace Elternbeirat.Web.Features.Home; public partial class Home { private static readonly CultureInfo German = CultureInfo.GetCultureInfo("de-DE"); [LoggerMessage(Level = LogLevel.Warning, Message = "Could not load posts for the home teaser from PocketBase.")] private static partial void LogLoadFailed(ILogger logger, Exception exception); [Inject] private PocketBaseClient PocketBase { get; set; } = default!; [Inject] private ILogger Logger { get; set; } = default!; private IReadOnlyList _latest = []; protected override async Task OnInitializedAsync() { try { // Show the three most recent posts as a teaser on the home page. var posts = await PocketBase.GetPostsAsync(); _latest = [.. posts.Take(3)]; } catch (HttpRequestException ex) { // Source unreachable -> show no teaser instead of a 500. LogLoadFailed(Logger, ex); } } }