Fix/pocketbase date timezone #33

Merged
Tom merged 9 commits from fix/pocketbase-date-timezone into main 2026-09-24 14:50:11 +02:00
3 changed files with 36 additions and 10 deletions
Showing only changes of commit d06af2891a - Show all commits

No files matched your search

+20
View File
@@ -13,6 +13,12 @@ namespace Elternbeirat.Contracts;
/// </remarks> /// </remarks>
public record Page public record Page
{ {
/// <summary>
/// The slug of the home page, which is served at the site root <c>/</c> rather
/// than at <c>/home</c>. Reserved: no other page may use it.
/// </summary>
private const string HomeSlug = "home";
/// <summary> /// <summary>
/// Gets the PocketBase record id. /// Gets the PocketBase record id.
/// </summary> /// </summary>
@@ -76,4 +82,18 @@ public record Page
/// </summary> /// </summary>
[JsonPropertyName("public")] [JsonPropertyName("public")]
public bool Public { get; init; } public bool Public { get; init; }
/// <summary>
/// Tests whether a slug is the home page's, ignoring case. This is the single
/// definition of that comparison, so every caller treats <c>home</c> and
/// <c>Home</c> alike.
/// </summary>
/// <param name="slug">
/// The slug to test.
/// </param>
/// <returns>
/// <see langword="true"/> if <paramref name="slug"/> is the home page's slug.
/// </returns>
public static bool IsHomeSlug(string slug) =>
string.Equals(slug, HomeSlug, StringComparison.OrdinalIgnoreCase);
} }
+12 -8
View File
@@ -1,3 +1,4 @@
using Elternbeirat.Contracts;
using Elternbeirat.PocketBase; using Elternbeirat.PocketBase;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
@@ -5,14 +6,18 @@ namespace Elternbeirat.Web.Features.Home;
public partial class Home public partial class Home
{ {
[LoggerMessage(Level = LogLevel.Warning, Message = "Could not load the home page from PocketBase.")] [LoggerMessage(
private static partial void LogLoadFailed(ILogger logger, Exception exception); Level = LogLevel.Warning,
Message = "Could not load the home page from PocketBase.")]
private static partial void LogLoadFailed(
ILogger logger,
Exception exception);
[Inject] [Inject]
private PocketBaseClient PocketBase { get; set; } = default!; private PocketBaseClient PocketBase { get; set; } = null!;
[Inject] [Inject]
private ILogger<Home> Logger { get; set; } = default!; private ILogger<Home> Logger { get; set; } = null!;
// Which dynamic blocks the home page shows is editorial: it comes from the // 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. // "home" page's embed field in PocketBase, not from hard-coded markup.
@@ -23,14 +28,13 @@ public partial class Home
try try
{ {
var pages = await PocketBase.GetPagesAsync(); var pages = await PocketBase.GetPagesAsync();
var home = pages.FirstOrDefault( var home = pages.FirstOrDefault(page => Page.IsHomeSlug(page.Slug));
p => string.Equals(p.Slug, "home", StringComparison.Ordinal));
_embed = home?.Embed ?? []; _embed = home?.Embed ?? [];
} }
catch (HttpRequestException ex) catch (HttpRequestException exception)
{ {
// Source unreachable -> render the intro without embeds instead of a 500. // Source unreachable -> render the intro without embeds instead of a 500.
LogLoadFailed(Logger, ex); LogLoadFailed(Logger, exception);
} }
} }
} }
@@ -17,7 +17,9 @@ public static class NavBuilder
public static IReadOnlyList<NavLinkItem> Footer(IReadOnlyList<Page> pages) => public static IReadOnlyList<NavLinkItem> Footer(IReadOnlyList<Page> pages) =>
Build(pages, "footer"); Build(pages, "footer");
private static List<NavLinkItem> Build(IReadOnlyList<Page> pages, string location) => private static List<NavLinkItem> Build(
IReadOnlyList<Page> pages,
string location) =>
[.. pages [.. pages
.Where(page => string.Equals(page.Location, location, StringComparison.Ordinal)) .Where(page => string.Equals(page.Location, location, StringComparison.Ordinal))
.OrderBy(page => page.Order) .OrderBy(page => page.Order)
@@ -27,5 +29,5 @@ public static class NavBuilder
// reached at "/{slug}", where either a literal route or the catch-all content // reached at "/{slug}", where either a literal route or the catch-all content
// page renders it. // page renders it.
private static string HrefFor(string slug) => private static string HrefFor(string slug) =>
string.Equals(slug, "home", StringComparison.Ordinal) ? "/" : $"/{slug}"; Page.IsHomeSlug(slug) ? "/" : $"/{slug}";
} }