45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using Elternbeirat.PocketBase;
|
|
using Elternbeirat.Web.Features.Layout;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace Elternbeirat.Web.Components.Layout;
|
|
|
|
public partial class MainLayout
|
|
{
|
|
[LoggerMessage(
|
|
Level = LogLevel.Warning,
|
|
Message = "Could not load navigation pages from PocketBase; the menu is empty.")]
|
|
private static partial void LogSourceUnavailable(ILogger logger, Exception exception);
|
|
|
|
[Inject]
|
|
private PocketBaseClient PocketBase { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private ILogger<MainLayout> Logger { get; set; } = null!;
|
|
|
|
[CascadingParameter]
|
|
private HttpContext? HttpContext { get; set; }
|
|
|
|
private IReadOnlyList<NavLinkItem> _header = [];
|
|
private IReadOnlyList<NavLinkItem> _footer = [];
|
|
|
|
// Berlin's year, not the server's (UTC) -- see FooterYear.
|
|
private readonly int _year = FooterYear.For(TimeProvider.System.GetUtcNow());
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
var pages = await PocketBase.GetPagesAsync(HttpContext?.RequestAborted ?? default);
|
|
_header = NavBuilder.Header(pages);
|
|
_footer = NavBuilder.Footer(pages);
|
|
}
|
|
catch (PocketBaseUnavailableException ex)
|
|
{
|
|
// Only the menu fails: render the chrome with an empty menu instead of a
|
|
// 500, so every page stays reachable. The brand link still leads home.
|
|
LogSourceUnavailable(Logger, ex);
|
|
}
|
|
}
|
|
}
|