41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using Elternbeirat.Contracts;
|
|
using Elternbeirat.PocketBase;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace Elternbeirat.Web.Features.Home;
|
|
|
|
public partial class Home
|
|
{
|
|
[LoggerMessage(
|
|
Level = LogLevel.Warning,
|
|
Message = "Could not load the home page from PocketBase.")]
|
|
private static partial void LogLoadFailed(
|
|
ILogger logger,
|
|
Exception exception);
|
|
|
|
[Inject]
|
|
private PocketBaseClient PocketBase { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private ILogger<Home> Logger { get; set; } = null!;
|
|
|
|
// Which dynamic blocks the home page shows is editorial: it comes from the
|
|
// "home" page's embed field in PocketBase, not from hard-coded markup.
|
|
private IReadOnlyList<string> _embed = [];
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
var pages = await PocketBase.GetPagesAsync();
|
|
var home = pages.FirstOrDefault(page => Page.IsHomeSlug(page.Slug));
|
|
_embed = home?.Embed ?? [];
|
|
}
|
|
catch (HttpRequestException exception)
|
|
{
|
|
// Source unreachable -> render the intro without embeds instead of a 500.
|
|
LogLoadFailed(Logger, exception);
|
|
}
|
|
}
|
|
}
|