diff --git a/My1kWordsEe/Components/Pages/WordPage.razor b/My1kWordsEe/Components/Pages/WordPage.razor index db92663..a27e5b1 100644 --- a/My1kWordsEe/Components/Pages/WordPage.razor +++ b/My1kWordsEe/Components/Pages/WordPage.razor @@ -22,13 +22,14 @@ @inject AddToFavoritesCommand AddToFavoritesCommand @inject RemoveFromFavoritesCommand RemoveFromFavoritesCommand @inject DeleteSampleSentenceCommand DeleteSampleSentenceCommand +@inject RedoSampleWordCommand RedoSampleWordCommand @code { [Inject] protected PreloadService PreloadService { get; set; } = default!; [Inject] protected ToastService ToastService { get; set; } = default!; - private ConfirmDialog DeleteSampleDialog = default!; + private ConfirmDialog ConfirmDialog = default!; [Parameter] public required string EeWord { get; init; } @@ -90,7 +91,7 @@ StateHasChanged(); } - private async Task DeleteSample(SampleSentence sampleSentence) + private async Task DeleteSampleSentence(SampleSentence sampleSentence) { var options = new ConfirmDialogOptions { @@ -100,7 +101,7 @@ AutoFocusYesButton = false, }; - var confirmation = await DeleteSampleDialog.ShowAsync( + var confirmation = await ConfirmDialog.ShowAsync( title: "Are you sure you want to delete this?", message1: "This will delete the record. Once deleted can not be rolled back.", message2: "Do you want to proceed?", options); @@ -126,6 +127,42 @@ } } + private async Task RedoSample() + { + var options = new ConfirmDialogOptions + { + IsScrollable = true, + Dismissable = true, + IsVerticallyCentered = true, + AutoFocusYesButton = false, + }; + + var confirmation = await ConfirmDialog.ShowAsync( + title: "Is this word described inadequately?", + message1: "This will regenerate the word explanation and all the samples will removed.", + message2: "Do you want to proceed?", options); + + if (confirmation) + { + PreloadService.Show(SpinnerColor.Light, "Saving data..."); + var redoResult = await this.RedoSampleWordCommand.Invoke(Value.EeWord); + if (redoResult.IsSuccess) + { + WordMetadata = redoResult; + StateHasChanged(); + } + else + { + ToastService.Notify(new ToastMessage(ToastType.Warning, redoResult.Error)); + } + PreloadService.Hide(); + } + else + { + ToastService.Notify(new ToastMessage(ToastType.Secondary, $"Redo action canceled.")); + } + } + private bool IsSampleGenerationInProgress = false; private async Task GenerateSample(MouseEventArgs e) @@ -190,7 +227,7 @@ @if (IsLoggedIn) { - + } @@ -224,7 +261,7 @@ {