47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|