46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using System.Collections.Frozen;
|
|
using Elternbeirat.Web.Shared;
|
|
|
|
namespace Elternbeirat.Web.Features.Home;
|
|
|
|
/// <summary>
|
|
/// Chooses the icon of a home page tile from the page's slug.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Pure presentation, so it lives in code: the schema has no icon field, and adding
|
|
/// one needs a schema change that cannot reach production yet. A page without an
|
|
/// entry here (e.g. one an editor just created) gets <see cref="Default"/>, so a
|
|
/// new page always shows up as a complete tile.
|
|
/// </remarks>
|
|
/// <seealso cref="IconSet"/>
|
|
public static class TileIcons
|
|
{
|
|
/// <summary>
|
|
/// The icon for a slug without its own entry: a generic page.
|
|
/// </summary>
|
|
public const string Default = "file-text";
|
|
|
|
/// <summary>
|
|
/// Icon name per slug. Every value must be a name in <see cref="IconSet"/>.
|
|
/// </summary>
|
|
private static readonly FrozenDictionary<string, string> Icons =
|
|
new Dictionary<string, string>
|
|
{
|
|
["board"] = "users",
|
|
["patrons"] = "heart-handshake",
|
|
["faqs"] = "help-circle",
|
|
["downloads"] = "download",
|
|
["posts"] = "newspaper",
|
|
["events"] = "calendar",
|
|
["contact"] = "mail",
|
|
}.ToFrozenDictionary(StringComparer.Ordinal);
|
|
|
|
/// <summary>
|
|
/// Returns the icon name for a page.
|
|
/// </summary>
|
|
/// <param name="slug">The page's slug, e.g. <c>board</c>.</param>
|
|
/// <returns>An icon name from <see cref="IconSet"/>; <see cref="Default"/> for an unknown slug.</returns>
|
|
public static string For(string slug) =>
|
|
Icons.GetValueOrDefault(slug, Default);
|
|
}
|