Show FAQ topics as an in-page accordion instead of drill-down pages
This commit is contained in:
1 parent
cb345975cb
commit
eacf95e041
7 files changed
+79
-162
No files matched your search
@@ -91,52 +91,22 @@ public sealed class PocketBaseClient(HttpClient httpClient)
|
||||
=> GetRecordsAsync<Faq>("faqs", "topic.order,order", token, expand: "topic");
|
||||
|
||||
/// <summary>
|
||||
/// Gets all public FAQ topics, ordered by <see cref="FaqTopic.Order"/>.
|
||||
/// Gets all public FAQ topics, ordered by <see cref="FaqTopic.Order"/>, each with
|
||||
/// its questions expanded.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Backs the FAQ overview, which lists the topics as links to their own pages.
|
||||
/// The questions are not loaded here; the topic page loads them per topic via
|
||||
/// <see cref="GetFaqTopicBySlugAsync"/>.
|
||||
/// Backs the FAQ page, which shows every topic as a collapsible group with its
|
||||
/// questions nested inside. The <c>faqs_via_topic</c> back-relation is expanded so
|
||||
/// one request returns the topics and their questions together; drafts among the
|
||||
/// questions are dropped in <see cref="FaqTopic.Faqs"/>.
|
||||
/// </remarks>
|
||||
/// <inheritdoc cref="GetPagesAsync" path="/param"/>
|
||||
/// <returns>
|
||||
/// The public FAQ topics, or an empty list if there are none.
|
||||
/// The public FAQ topics with their questions, or an empty list if there are none.
|
||||
/// </returns>
|
||||
/// <inheritdoc cref="GetPagesAsync" path="/exception"/>
|
||||
public Task<IReadOnlyList<FaqTopic>> GetFaqTopicsAsync(CancellationToken token = default)
|
||||
=> GetRecordsAsync<FaqTopic>("faq_topics", "order", token);
|
||||
|
||||
/// <summary>
|
||||
/// Gets one public FAQ topic by its slug, with its questions expanded, or
|
||||
/// <see langword="null"/> when no public topic has that slug.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Backs the topic's own page at <c>/faqs/{slug}</c>: it loads the single topic
|
||||
/// and, through the <c>faqs_via_topic</c> back-relation, the questions grouped
|
||||
/// under it, so the page needs one request. The slug is unique, so at most one
|
||||
/// record matches.
|
||||
/// </remarks>
|
||||
/// <param name="slug">
|
||||
/// The topic slug from the URL, e.g. <c>"cafeteria"</c>.
|
||||
/// </param>
|
||||
/// <inheritdoc cref="GetPagesAsync" path="/param[@name='token']"/>
|
||||
/// <returns>
|
||||
/// The matching public topic with its questions, or <see langword="null"/> if
|
||||
/// none matches.
|
||||
/// </returns>
|
||||
/// <inheritdoc cref="GetPagesAsync" path="/exception"/>
|
||||
public async Task<FaqTopic?> GetFaqTopicBySlugAsync(
|
||||
string slug,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var topics = await GetRecordsAsync<FaqTopic>(
|
||||
"faq_topics",
|
||||
"order",
|
||||
token,
|
||||
expand: "faqs_via_topic");
|
||||
return topics.FirstOrDefault(
|
||||
topic => string.Equals(topic.Slug, slug, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
=> GetRecordsAsync<FaqTopic>("faq_topics", "order", token, expand: "faqs_via_topic");
|
||||
|
||||
/// <summary>
|
||||
/// Gets all public records of a collection in a single request.
|
||||
|
||||
Reference in new issue
Block a user