Group FAQs by a topic relation, ordered; drop unused FAQ teaser

This commit is contained in:
tleininger committed 2026-09-29 22:11:30 +02:00
1 parent 28944c155a
commit 2ea8856d65
14 files changed
+328 -128

No files matched your search

@@ -1,16 +0,0 @@
@if (_faqs.Count > 0)
{
<section class="embed embed-faqs">
<h2>Häufige Fragen</h2>
@foreach (var faq in _faqs)
{
<details class="faq-item">
<summary>@faq.Question</summary>
<div class="faq-answer">
@((MarkupString)Markdown.ToHtml(faq.Answer))
</div>
</details>
}
<p class="embed-more"><a href="/faqs">Alle Fragen <span aria-hidden="true">&rarr;</span></a></p>
</section>
}
@@ -1,46 +0,0 @@
using Elternbeirat.Contracts;
using Elternbeirat.PocketBase;
using Microsoft.AspNetCore.Components;
namespace Elternbeirat.Web.Features.Embeds;
public partial class FaqsEmbed
{
// Number of questions shown in the teaser; the full hub is one link away.
private const int TeaserCount = 3;
[LoggerMessage(
Level = LogLevel.Warning,
Message = "Could not load FAQs for an embed from PocketBase; the teaser is omitted.")]
private static partial void LogSourceUnavailable(
ILogger logger,
Exception exception);
[Inject]
private PocketBaseClient PocketBase { get; set; } = null!;
[Inject]
private ILogger<FaqsEmbed> Logger { get; set; } = null!;
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
private IReadOnlyList<Faq> _faqs = [];
protected override async Task OnInitializedAsync()
{
try
{
// GetFaqsAsync is ordered by topic, then question, so the first entries
// the teaser takes are stable across requests.
var faqs = await PocketBase.GetFaqsAsync(HttpContext?.RequestAborted ?? CancellationToken.None);
_faqs = [.. faqs.Take(TeaserCount)];
}
catch (PocketBaseUnavailableException exception)
{
// Only part of the page fails: omit the teaser, keep the page (and its
// 200) intact. A missing teaser is degraded, not broken.
LogSourceUnavailable(Logger, exception);
}
}
}
@@ -1,5 +0,0 @@
/* Card styles for .faq-item are shared with the full FAQ page and live in the
global app.css. Only the embed's spacing on the home page is specific here. */
.embed-faqs {
margin-top: var(--space-5);
}
@@ -12,14 +12,11 @@
case "events":
<EventsEmbed />
break;
case "faqs":
<FaqsEmbed />
break;
}
}
@code {
/// <summary>The page's embed keys ("posts", "events", "faqs"), in order.</summary>
/// <summary>The page's embed keys ("posts", "events"), in order.</summary>
[Parameter]
public IReadOnlyList<string> Embed { get; set; } = [];
}