[frontend/components] Use global dialogs for emoji management actions
This commit is contained in:
parent
0951728f0a
commit
9ee200c50e
1 changed files with 79 additions and 32 deletions
|
@ -5,7 +5,7 @@
|
||||||
@using Iceshrimp.Frontend.Core.Miscellaneous
|
@using Iceshrimp.Frontend.Core.Miscellaneous
|
||||||
@using Iceshrimp.Frontend.Core.Services
|
@using Iceshrimp.Frontend.Core.Services
|
||||||
@inject ApiService Api;
|
@inject ApiService Api;
|
||||||
@inject IJSRuntime Js;
|
@inject GlobalComponentSvc Global;
|
||||||
@inject IStringLocalizer<Localization> Loc;
|
@inject IStringLocalizer<Localization> Loc;
|
||||||
|
|
||||||
<div @ref="EmojiButton" class="emoji-entry" @onclick="SelectEmoji" @onclick:stopPropagation="true">
|
<div @ref="EmojiButton" class="emoji-entry" @onclick="SelectEmoji" @onclick:stopPropagation="true">
|
||||||
|
@ -91,22 +91,24 @@
|
||||||
{
|
{
|
||||||
// Remote emojis endpoint sets EmojiResponse.Category to the emoji's host
|
// Remote emojis endpoint sets EmojiResponse.Category to the emoji's host
|
||||||
var res = await Api.Emoji.CloneEmojiAsync(Emoji.Name, Emoji.Category);
|
var res = await Api.Emoji.CloneEmojiAsync(Emoji.Name, Emoji.Category);
|
||||||
if (res != null) await Js.InvokeVoidAsync("alert", $"Cloned {Emoji.Name}");
|
if (res != null) await Global.NoticeDialog?.Display(Loc["Cloned {0} from {1}", Emoji.Name, Emoji.Category])!;
|
||||||
}
|
}
|
||||||
catch (ApiException e)
|
catch (ApiException e)
|
||||||
{
|
{
|
||||||
await Js.InvokeVoidAsync("alert", e.Response.Message);
|
await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Rename()
|
private async Task Rename() =>
|
||||||
|
await Global.PromptDialog?.Prompt(new EventCallback<string?>(this, RenameCallback), Loc["Rename emoji"], "", Emoji.Name, buttonText: Loc["Rename"])!;
|
||||||
|
|
||||||
|
private async Task RenameCallback(string? name)
|
||||||
{
|
{
|
||||||
var name = await Js.InvokeAsync<string?>("prompt", "Rename emoji", Emoji.Name);
|
|
||||||
if (string.IsNullOrWhiteSpace(name)) return;
|
if (string.IsNullOrWhiteSpace(name)) return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { Name = name.Trim() });
|
var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { Name = name });
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
Emoji.Name = res.Name;
|
Emoji.Name = res.Name;
|
||||||
|
@ -115,11 +117,13 @@
|
||||||
}
|
}
|
||||||
catch (ApiException e)
|
catch (ApiException e)
|
||||||
{
|
{
|
||||||
await Js.InvokeVoidAsync("alert", e.Response.Message);
|
await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task MarkSensitive(bool sensitive)
|
private async Task MarkSensitive(bool sensitive)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { Sensitive = sensitive });
|
var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { Sensitive = sensitive });
|
||||||
if (res != null)
|
if (res != null)
|
||||||
|
@ -128,53 +132,96 @@
|
||||||
StateHasChanged();
|
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 MarkNotSensitive() => await MarkSensitive(false);
|
||||||
|
|
||||||
private async Task MarkAsSensitive() => await MarkSensitive(true);
|
private async Task MarkAsSensitive() => await MarkSensitive(true);
|
||||||
|
|
||||||
private async Task SetAliases()
|
private async Task SetAliases() =>
|
||||||
|
await Global.PromptDialog?.Prompt(new EventCallback<string?>(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)
|
||||||
{
|
{
|
||||||
var aliases = await Js.InvokeAsync<string?>("prompt", "Set aliases (separated by comma , )", Emoji.License ?? "");
|
|
||||||
if (aliases == null) return;
|
if (aliases == null) return;
|
||||||
|
|
||||||
var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { Aliases = string.IsNullOrWhiteSpace(aliases) ? null : aliases.Replace(" ", "").Split(",").ToList() });
|
try
|
||||||
|
{
|
||||||
|
var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { Aliases = string.IsNullOrWhiteSpace(aliases) ? [] : aliases.Replace(" ", "").Split("\n").ToList() });
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
Emoji.Aliases = res.Aliases;
|
Emoji.Aliases = res.Aliases;
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (ApiException e)
|
||||||
private async Task SetCategory()
|
{
|
||||||
|
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<string?>(this, SetCategoryCallback), Loc["Set category"], "", Emoji.Category, true)!;
|
||||||
|
|
||||||
|
private async Task SetCategoryCallback(string? category)
|
||||||
{
|
{
|
||||||
var category = await Js.InvokeAsync<string?>("prompt", "Set category", Emoji.Category ?? "");
|
|
||||||
if (category == null) return;
|
if (category == null) return;
|
||||||
|
|
||||||
var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { Category = category.Trim() });
|
try
|
||||||
|
{
|
||||||
|
var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { Category = category });
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
Emoji.Category = res.Category;
|
Emoji.Category = res.Category;
|
||||||
await GetEmojis.InvokeAsync();
|
await GetEmojis.InvokeAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (ApiException e)
|
||||||
private async Task SetLicense()
|
{
|
||||||
|
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<string?>(this, SetLicenseCallback), Loc["Set license"], "", Emoji.License, true, true)!;
|
||||||
|
|
||||||
|
private async Task SetLicenseCallback(string? license)
|
||||||
{
|
{
|
||||||
var license = await Js.InvokeAsync<string?>("prompt", "Set license", Emoji.License ?? "");
|
|
||||||
if (license == null) return;
|
if (license == null) return;
|
||||||
|
|
||||||
var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { License = string.IsNullOrWhiteSpace(license) ? null : license.Trim() });
|
try
|
||||||
|
{
|
||||||
|
var res = await Api.Emoji.UpdateEmojiAsync(Emoji.Id, new UpdateEmojiRequest { License = license });
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
Emoji.License = res.License;
|
Emoji.License = res.License;
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async Task Delete()
|
private async Task Delete() =>
|
||||||
|
await Global.ConfirmDialog?.Confirm(new EventCallback<bool>(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);
|
var res = await Api.Emoji.DeleteEmojiAsync(Emoji.Id);
|
||||||
if (res) await GetEmojis.InvokeAsync();
|
if (res) await GetEmojis.InvokeAsync();
|
||||||
}
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue