@using Iceshrimp.Frontend.Localization @using Iceshrimp.Shared.Schemas.Web @using Microsoft.Extensions.Localization @using Iceshrimp.Assets.PhosphorIcons @using Iceshrimp.Frontend.Core.Miscellaneous @using Iceshrimp.Frontend.Core.Services @inject ApiService Api; @inject GlobalComponentSvc Global; @inject IStringLocalizer Loc;
@Emoji.Name @foreach (var alias in Emoji.Aliases) { @alias } @if (Source == "remote") { } @if (Emoji.Sensitive) { } @if (!string.IsNullOrWhiteSpace(Emoji.License)) { }
@if (Source == "remote") { @Loc["Clone"] } else { @Loc["Rename"] @if (Emoji.Sensitive) { @Loc["Mark as not sensitive"] } else { @Loc["Mark as sensitive"] } @Loc["Set aliases"] @Loc["Set category"] @Loc["Set license"] @Loc["Delete"] }
@code { [Parameter, EditorRequired] public required EmojiResponse Emoji { get; set; } [Parameter, EditorRequired] public required string Source { get; set; } [Parameter, EditorRequired] public required EventCallback GetEmojis { get; set; } private ElementReference EmojiButton { get; set; } private Menu EmojiMenu { get; set; } = null!; private void SelectEmoji() => EmojiMenu.Toggle(EmojiButton); private async Task Clone() { if (Source == "local" || Emoji.Category == null) return; try { // Remote emojis endpoint sets EmojiResponse.Category to the emoji's host var res = await Api.Emoji.CloneEmojiAsync(Emoji.Name, Emoji.Category); if (res != null) await Global.NoticeDialog?.Display(Loc["Cloned {0} from {1}", Emoji.Name, Emoji.Category])!; } catch (ApiException e) { await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!; } } private async Task Rename() => await Global.PromptDialog?.Prompt(new EventCallback(this, RenameCallback), Loc["Rename emoji"], "", Emoji.Name, buttonText: Loc["Rename"])!; private async Task RenameCallback(string? name) { if (string.IsNullOrWhiteSpace(name)) return; try { var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { Name = name }); if (res != null) { Emoji.Name = res.Name; StateHasChanged(); } } catch (ApiException e) { await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!; } } private async Task MarkSensitive(bool sensitive) { try { var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { Sensitive = sensitive }); if (res != null) { Emoji.Sensitive = res.Sensitive; StateHasChanged(); } } catch (ApiException e) { await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!; } } private async Task MarkNotSensitive() => await MarkSensitive(false); private async Task MarkAsSensitive() => await MarkSensitive(true); private async Task SetAliases() => await Global.PromptDialog?.Prompt(new EventCallback(this, SetAliasesCallback), Loc["Set aliases (separated by new line)"], "one\ntwo\nthree", string.Join("\n", Emoji.Aliases), true, true)!; private async Task SetAliasesCallback(string? aliases) { if (aliases == null) return; try { var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { Aliases = string.IsNullOrWhiteSpace(aliases) ? [] : aliases.Replace(" ", "").Split("\n").ToList() }); if (res != null) { Emoji.Aliases = res.Aliases; StateHasChanged(); } } catch (ApiException e) { await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!; } } private async Task SetCategory() => await Global.PromptDialog?.Prompt(new EventCallback(this, SetCategoryCallback), Loc["Set category"], "", Emoji.Category, true)!; private async Task SetCategoryCallback(string? category) { if (category == null) return; try { var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { Category = category }); if (res != null) { Emoji.Category = res.Category; await GetEmojis.InvokeAsync(); } } catch (ApiException e) { await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!; } } private async Task SetLicense() => await Global.PromptDialog?.Prompt(new EventCallback(this, SetLicenseCallback), Loc["Set license"], "", Emoji.License, true, true)!; private async Task SetLicenseCallback(string? license) { if (license == null) return; try { var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { License = license }); if (res != null) { Emoji.License = res.License; StateHasChanged(); } } catch (ApiException e) { await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!; } } private async Task Delete() => await Global.ConfirmDialog?.Confirm(new EventCallback(this, DeleteCallback), Loc["Delete {0}?", Emoji.Name], Icons.Trash, Loc["Delete"])!; private async Task DeleteCallback(bool delete) { if (!delete) return; try { var res = await Api.Emoji.DeleteEmojiAsync(Emoji.Id); if (res) await GetEmojis.InvokeAsync(); } catch (ApiException e) { await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!; } } }