Group FAQs by a topic relation, ordered; drop unused FAQ teaser
This commit is contained in:
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">→</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; } = [];
|
||||
}
|
||||
@@ -17,7 +17,7 @@ else
|
||||
@foreach (var group in _groups)
|
||||
{
|
||||
<section class="faq-topic">
|
||||
<h2>@group.Key</h2>
|
||||
<h2>@group.Key.Title</h2>
|
||||
@foreach (var faq in group)
|
||||
{
|
||||
<details class="faq-item">
|
||||
|
||||
@@ -23,7 +23,7 @@ public partial class FaqList
|
||||
[CascadingParameter]
|
||||
private HttpContext? HttpContext { get; set; }
|
||||
|
||||
private IReadOnlyList<IGrouping<string, Faq>> _groups = [];
|
||||
private IReadOnlyList<IGrouping<FaqTopic, Faq>> _groups = [];
|
||||
|
||||
// Set when the content source could not be reached or read. The markup then
|
||||
// shows a "temporarily unavailable" note instead of "no questions", matching
|
||||
@@ -35,7 +35,12 @@ public partial class FaqList
|
||||
try
|
||||
{
|
||||
var faqs = await PocketBase.GetFaqsAsync(HttpContext?.RequestAborted ?? CancellationToken.None);
|
||||
_groups = [.. faqs.GroupBy(faq => faq.Topic)];
|
||||
|
||||
// GetFaqsAsync sorts by topic.order first, so grouping in encounter order
|
||||
// keeps the topic groups in the order an editor gave the topics. Entries
|
||||
// without an expanded topic have no group and are skipped rather than
|
||||
// grouped under a null heading.
|
||||
_groups = [.. faqs.Where(faq => faq.Topic is not null).GroupBy(faq => faq.Topic!)];
|
||||
}
|
||||
catch (PocketBaseUnavailableException exception)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user