@using AngleSharp.Text @using Iceshrimp.Frontend.Core.Services @using Iceshrimp.Shared.Schemas.Web @inject EmojiService EmojiService @inject GlobalComponentSvc GlobalComponentSvc @inject IJSRuntime Js
@foreach (var category in Categories) {
@category.Key
@foreach (var emoji in category.Value) {
}
}
@code { private EventCallback OnEmojiSelect { get; set; } private List EmojiList { get; set; } = []; private ElementReference EmojiPickerRef { get; set; } private float _top; private float _left; private IJSInProcessObjectReference _module = null!; private string EmojiFilter { get; set; } = ""; private Dictionary> Categories { get; set; } = []; protected override async Task OnInitializedAsync() { GlobalComponentSvc.EmojiPicker = this; EmojiList = await EmojiService.GetEmojiAsync(); _module = (IJSInProcessObjectReference)await Js.InvokeAsync("import", "./Components/EmojiPicker.razor.js"); FilterEmojis(); } private async Task Select(EmojiResponse emoji) { await OnEmojiSelect.InvokeAsync(emoji); Close(); } private void Close() { _module.InvokeVoid("closeDialog", EmojiPickerRef); } public void Open(ElementReference root, EventCallback func) { OnEmojiSelect = func; var pos = _module.Invoke>("getPosition", root); _left = pos[0]; _top = pos[1]; StateHasChanged(); _module.InvokeVoid("openDialog", EmojiPickerRef); } private void FilterEmojis() { Categories = EmojiList .Where(p => p.Name.Contains(EmojiFilter.StripLeadingTrailingSpaces()) || p.Aliases.Count(a => a.Contains(EmojiFilter.StripLeadingTrailingSpaces())) != 0) .OrderBy(p => p.Name) .ThenBy(p => p.Id) .GroupBy(p => p.Category) .OrderBy(p => string.IsNullOrEmpty(p.Key)) .ThenBy(p => p.Key) .ToDictionary(p => p.Key ?? "Other", p => p.ToList()); } }