37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System.Globalization;
|
|
using Elternbeirat.Contracts;
|
|
using Elternbeirat.PocketBase;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace Elternbeirat.Web.Features.Posts;
|
|
|
|
public partial class PostList
|
|
{
|
|
[LoggerMessage(Level = LogLevel.Warning, Message = "Could not load posts from PocketBase.")]
|
|
private static partial void LogLoadFailed(ILogger logger, Exception exception);
|
|
|
|
private static readonly CultureInfo German = CultureInfo.GetCultureInfo("de-DE");
|
|
|
|
[Inject]
|
|
private PocketBaseClient PocketBase { get; set; } = default!;
|
|
|
|
[Inject]
|
|
private ILogger<PostList> Logger { get; set; } = default!;
|
|
|
|
private IReadOnlyList<Post> _posts = [];
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
_posts = await PocketBase.GetPostsAsync();
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
// Source unreachable -> show an empty list instead of a 500. The page
|
|
// stays up; the "keine Beiträge" note is rendered.
|
|
LogLoadFailed(Logger, ex);
|
|
}
|
|
}
|
|
}
|