@page "/mod/emojis" @using Iceshrimp.Frontend.Core.Services @using Iceshrimp.Frontend.Localization @using Microsoft.AspNetCore.Authorization @using Microsoft.Extensions.Localization @using Microsoft.AspNetCore.Components.Sections @using Iceshrimp.Assets.PhosphorIcons @using Iceshrimp.Frontend.Core.Miscellaneous @using Iceshrimp.Shared.Schemas.Web @using Iceshrimp.Frontend.Components @attribute [Authorize(Roles = "moderator")] @layout ModerationLayout @inject ApiService Api; @inject IStringLocalizer Loc; @Loc["Custom Emojis"] @if (State is State.Loaded) {
@foreach (var category in Categories) { @category.Key
@foreach (var emoji in category.Value) { }
}
} @if (State is State.Empty) {
This instance has no emojis
} @if (State is State.Loading) {
} @code { private List Emojis { get; set; } = []; private Dictionary> Categories { get; set; } = new(); private string EmojiFilter { get; set; } = ""; private string HostFilter { get; set; } = ""; private string Source { get; set; } = "local"; private State State { get; set; } private void FilterEmojis() { Categories = Emojis .Where(p => p.Name.Contains(EmojiFilter.Trim()) || p.Aliases.Count(a => a.Contains(EmojiFilter.Trim())) != 0) .OrderBy(p => p.Name) .ThenBy(p => p.Id) .GroupBy(p => p.Category) .Where(p => Source == "local" || (Source == "remote" && (p.Key?.Contains(HostFilter) ?? false))) .OrderBy(p => string.IsNullOrEmpty(p.Key)) .ThenBy(p => p.Key) .ToDictionary(p => p.Key ?? "Other", p => p.ToList()); } private async Task GetEmojis() { State = State.Loading; Emojis = Source == "remote" ? await Api.Emoji.GetRemoteEmojiAsync() : await Api.Emoji.GetAllEmojiAsync(); if (Emojis.Count == 0) { State = State.Empty; } else { FilterEmojis(); State = State.Loaded; } } protected override async Task OnInitializedAsync() { await GetEmojis(); } }