Show FAQ topics as an in-page accordion instead of drill-down pages

This commit is contained in:
tleininger committed 2026-09-30 16:21:49 +02:00
1 parent cb345975cb
commit eacf95e041
7 files changed
+79 -162

No files matched your search

+19 -12
View File
@@ -25,16 +25,23 @@ else if (_topics.Count == 0)
}
else
{
<ul class="faq-topic-list">
@foreach (var topic in _topics)
{
<li>
<h2><a href="@($"/faqs/{topic.Slug}")">@topic.Title</a></h2>
@if (!string.IsNullOrWhiteSpace(topic.Intro))
{
<div class="faq-topic-intro">@((MarkupString)Markdown.ToHtml(topic.Intro))</div>
}
</li>
}
</ul>
@foreach (var topic in _topics)
{
<details class="faq-topic">
<summary>@topic.Title</summary>
@if (!string.IsNullOrWhiteSpace(topic.Intro))
{
<div class="faq-topic-intro">@((MarkupString)Markdown.ToHtml(topic.Intro))</div>
}
@foreach (var faq in topic.Faqs)
{
<details class="faq-item">
<summary>@faq.Question</summary>
<div class="faq-answer">
@((MarkupString)Markdown.ToHtml(faq.Answer))
</div>
</details>
}
</details>
}
}
@@ -1,30 +0,0 @@
@page "/faqs/{Slug}"
@if (_unavailable)
{
<PageTitle>Vorübergehend nicht erreichbar</PageTitle>
<p>Das Thema ist gerade nicht erreichbar. Bitte später erneut versuchen.</p>
}
else if (_topic is not null)
{
<PageTitle>@_topic.Title</PageTitle>
<nav>
<a href="/faqs">&larr; Alle Themen</a>
</nav>
<h1>@_topic.Title</h1>
@if (!string.IsNullOrWhiteSpace(_topic.Intro))
{
<div class="faq-topic-intro">@((MarkupString)Markdown.ToHtml(_topic.Intro))</div>
}
@foreach (var faq in _topic.Faqs)
{
<details class="faq-item">
<summary>@faq.Question</summary>
<div class="faq-answer">
@((MarkupString)Markdown.ToHtml(faq.Answer))
</div>
</details>
}
}
@* No topic and not unavailable: the slug was unknown; NavigationManager.NotFound()
already ran in OnParametersSetAsync and renders the not-found page. *@
@@ -1,63 +0,0 @@
using Elternbeirat.Contracts;
using Elternbeirat.PocketBase;
using Elternbeirat.Web.Shared;
using Microsoft.AspNetCore.Components;
namespace Elternbeirat.Web.Features.Faqs;
public partial class FaqTopicDetail
{
[LoggerMessage(
Level = LogLevel.Error,
Message = "Could not load FAQ topic '{Slug}' from PocketBase; content source is unavailable.")]
private static partial void LogSourceUnavailable(
ILogger logger,
string slug,
Exception exception);
[Parameter]
public string Slug { get; set; } = string.Empty;
[Inject]
private PocketBaseClient PocketBase { get; set; } = null!;
[Inject]
private ILogger<FaqTopicDetail> Logger { get; set; } = null!;
[Inject]
private NavigationManager Navigation { get; set; } = null!;
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
private FaqTopic? _topic;
// Set when the content source could not be reached or read. The markup then
// shows a "temporarily unavailable" note instead of a not-found page, matching
// the 503 this sets on the response.
private bool _unavailable;
protected override async Task OnParametersSetAsync()
{
try
{
_topic = await PocketBase.GetFaqTopicBySlugAsync(
Slug,
HttpContext?.RequestAborted ?? CancellationToken.None);
}
catch (PocketBaseUnavailableException exception)
{
// The site works, its data store is down: 503, not 404.
LogSourceUnavailable(Logger, Slug, exception);
_unavailable = true;
SourceUnavailable.SetStatus(HttpContext);
return;
}
if (_topic is null)
{
// The source answered, but there is no topic with this slug: a genuine 404.
Navigation.NotFound();
}
}
}