Files
Elternbeirat/Elternbeirat.Web/Features/Embeds/PostsEmbed.razor.cs
T

38 lines
1.1 KiB
C#

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