diff --git a/JSMR.UI.Blazor/Components/Modals/TagEnglishNameModal.razor b/JSMR.UI.Blazor/Components/Modals/TagEnglishNameModal.razor new file mode 100644 index 0000000..9328af3 --- /dev/null +++ b/JSMR.UI.Blazor/Components/Modals/TagEnglishNameModal.razor @@ -0,0 +1,19 @@ +@inherits FeedbackComponent + +@using AntDesign +@using JSMR.UI.Blazor.Models + +
+ +
+ +@code { + [CascadingParameter] + public ModalRef ModalRef { get; set; } = default!; + + public override async Task OnFeedbackOkAsync(ModalClosingEventArgs args) + { + await base.OnFeedbackOkAsync(args); + await CloseFeedbackAsync(); + } +} \ No newline at end of file diff --git a/JSMR.UI.Blazor/Models/SetEnglishTagNameModel.cs b/JSMR.UI.Blazor/Models/SetEnglishTagNameModel.cs new file mode 100644 index 0000000..6055c42 --- /dev/null +++ b/JSMR.UI.Blazor/Models/SetEnglishTagNameModel.cs @@ -0,0 +1,8 @@ +namespace JSMR.UI.Blazor.Models; + +public class SetEnglishTagNameModel +{ + public required string TagName { get; set; } + public string? CurrentEnglishTagName { get; set; } + public string? UpdatedEnglishTagName { get; set; } +} \ No newline at end of file diff --git a/JSMR.UI.Blazor/Pages/Tags.razor b/JSMR.UI.Blazor/Pages/Tags.razor index d8ef36e..154d143 100644 --- a/JSMR.UI.Blazor/Pages/Tags.razor +++ b/JSMR.UI.Blazor/Pages/Tags.razor @@ -3,12 +3,15 @@ @inject IJSRuntime JS @using AntDesign @using JSMR.Application.Common.Search +@using JSMR.Application.Tags.Commands.SetEnglishName @using JSMR.Application.Tags.Commands.UpdateTagStatus @using JSMR.Application.Tags.Contracts @using JSMR.Application.Tags.Queries.Search @using JSMR.Application.Tags.Queries.Search.Contracts @using JSMR.UI.Blazor.Components +@using JSMR.UI.Blazor.Components.Modals @using JSMR.UI.Blazor.Filters +@using JSMR.UI.Blazor.Models @using JSMR.UI.Blazor.Services @using Microsoft.AspNetCore.WebUtilities @@ -55,18 +58,21 @@ - @if (!context.Favorite) - { - Set as Favorite - } - @if (!context.Blacklisted) - { - Set as Blacklisted - } - @if (context.Favorite || context.Blacklisted) - { - Set as Neutral - } + + @if (!context.Favorite) + { + Favorite + } + @if (!context.Blacklisted) + { + Blacklisted + } + @if (context.Favorite || context.Blacklisted) + { + Neutral + } + + Set English Name... @@ -145,6 +151,12 @@ [Inject] INotificationService NotificationService { get; set; } = default!; + [Inject] + IMessageService MessageService { get; set; } = default!; + + [Inject] + ModalService ModalService { get; set; } = default!; + public string? Keywords { get; set; } public int PageNumber { get; set; } = 1; public int PageSize { get; set; } = 100; @@ -328,4 +340,52 @@ await NotificationService.Open(config); } + + private async Task OpenSetEnglishNameModal(TagSearchItem item) + { + SetEnglishTagNameModel model = new() + { + TagName = item.Name, + CurrentEnglishTagName = item.EnglishName, + UpdatedEnglishTagName = item.EnglishName + }; + + ModalOptions modalOptions = new() + { + Title = $"Set English Name: {item.Name}", + MaskClosable = false, + Centered = true, + OkText = "Save", + OnOk = async (args) => + { + await SetEnglishName(item, model.UpdatedEnglishTagName); + } + }; + + ModalService.CreateModal(modalOptions, model); + } + + private async Task SetEnglishName(TagSearchItem item, string? englishName) + { + SetTagEnglishNameRequest request = new( + TagId: item.TagId, + EnglishName: englishName ?? string.Empty + ); + + SetTagEnglishNameResponse? response = await Client.SetTagEnglishNameAsync(request); + + if (response is null) + return; + + item.EnglishName = response.EnglishName; + + await InvokeAsync(StateHasChanged); + + await NotificationService.Open(new NotificationConfig + { + Message = "Tag English Name Updated", + Description = $"Tag '{item.Name}' English name set to '{response.EnglishName}'.", + Placement = NotificationPlacement.Top + }); + } } \ No newline at end of file diff --git a/JSMR.UI.Blazor/Services/VoiceWorksClient.cs b/JSMR.UI.Blazor/Services/VoiceWorksClient.cs index abafada..6c8aa1c 100644 --- a/JSMR.UI.Blazor/Services/VoiceWorksClient.cs +++ b/JSMR.UI.Blazor/Services/VoiceWorksClient.cs @@ -1,6 +1,7 @@ using JSMR.Application.Circles.Queries.Search; using JSMR.Application.Creators.Commands.UpdateCreatorStatus; using JSMR.Application.Creators.Queries.Search; +using JSMR.Application.Tags.Commands.SetEnglishName; using JSMR.Application.Tags.Commands.UpdateTagStatus; using JSMR.Application.Tags.Queries.Search; using JSMR.Application.VoiceWorks.Queries.Search; @@ -50,6 +51,12 @@ public class VoiceWorksClient(HttpClient http) return await resp.Content.ReadFromJsonAsync(JsonOptions, cancellationToken: ct); } + public async Task SetTagEnglishNameAsync(SetTagEnglishNameRequest request, CancellationToken ct = default) + { + using var resp = await http.PostAsJsonAsync("/api/tags/set-english-name", request, ct); + return await resp.Content.ReadFromJsonAsync(JsonOptions, cancellationToken: ct); + } + public async Task UpdateCreatorStatusAsync(UpdateCreatorStatusRequest request, CancellationToken ct = default) { using var resp = await http.PostAsJsonAsync("/api/creators/update-status", request, ct);