From 0cf93562802f17e91aee88530a09f20611223382 Mon Sep 17 00:00:00 2001 From: Gianluigi Liguori Date: Sat, 3 Feb 2024 13:13:05 +0100 Subject: [PATCH] Disable buttons when operation running --- src/Savings.SPA/Pages/FixedItemEdit.razor | 8 ++-- src/Savings.SPA/Pages/FixedItemEdit.razor.cs | 29 +++++++++--- .../Pages/RecurrencyAdjustment.razor | 4 +- .../Pages/RecurrencyAdjustment.razor.cs | 44 ++++++++++++------- src/Savings.SPA/Pages/RecurrentItemEdit.razor | 8 ++-- .../Pages/RecurrentItemEdit.razor.cs | 12 +++++ 6 files changed, 77 insertions(+), 28 deletions(-) diff --git a/src/Savings.SPA/Pages/FixedItemEdit.razor b/src/Savings.SPA/Pages/FixedItemEdit.razor index 5b506a5..0d0fe0d 100644 --- a/src/Savings.SPA/Pages/FixedItemEdit.razor +++ b/src/Savings.SPA/Pages/FixedItemEdit.razor @@ -69,15 +69,17 @@
- - @if (!isNew) { - + }
diff --git a/src/Savings.SPA/Pages/FixedItemEdit.razor.cs b/src/Savings.SPA/Pages/FixedItemEdit.razor.cs index 4820d71..fd8163f 100644 --- a/src/Savings.SPA/Pages/FixedItemEdit.razor.cs +++ b/src/Savings.SPA/Pages/FixedItemEdit.razor.cs @@ -28,6 +28,8 @@ public partial class FixedItemEdit : ComponentBase bool Credit { get; set; } = false; + public bool OperationRunning { get; set; } = false; + public MoneyCategory[] Categories { get; set; } InputNumber amountInputNumber; @@ -74,11 +76,23 @@ bool ValidateData() async Task Delete() { - var res = await dialogService.Confirm("Are you sure you want delete?", "Delete fixed item", new ConfirmOptions() { OkButtonText = "Yes", CancelButtonText = "No" }); - if (res.HasValue && res.Value) + try { - var deletedItem = await savingsAPI.DeleteFixedMoneyItem(fixedItemToEdit.ID); - this.dialogService.Close(true); + OperationRunning = true; + var res = await dialogService.Confirm("Are you sure you want delete?", "Delete fixed item", new ConfirmOptions() { OkButtonText = "Yes", CancelButtonText = "No" }); + if (res.HasValue && res.Value) + { + var deletedItem = await savingsAPI.DeleteFixedMoneyItem(fixedItemToEdit.ID); + this.dialogService.Close(true); + } + } + catch (Exception) + { + throw; + } + finally + { + OperationRunning = false; } } @@ -87,6 +101,7 @@ private async void OnValidSubmit() { try { + OperationRunning = true; if (!ValidateData()) return; if (Incoming) { @@ -113,10 +128,14 @@ private async void OnValidSubmit() } this.dialogService.Close(true); } - catch(Exception ex) + catch (Exception ex) { notificationService.Notify(NotificationSeverity.Error, "Attention", ex.Message); } + finally + { + OperationRunning = false; + } } diff --git a/src/Savings.SPA/Pages/RecurrencyAdjustment.razor b/src/Savings.SPA/Pages/RecurrencyAdjustment.razor index af472ff..46aafdf 100644 --- a/src/Savings.SPA/Pages/RecurrencyAdjustment.razor +++ b/src/Savings.SPA/Pages/RecurrencyAdjustment.razor @@ -20,10 +20,10 @@
- -
diff --git a/src/Savings.SPA/Pages/RecurrencyAdjustment.razor.cs b/src/Savings.SPA/Pages/RecurrencyAdjustment.razor.cs index 9f92a20..caa756e 100644 --- a/src/Savings.SPA/Pages/RecurrencyAdjustment.razor.cs +++ b/src/Savings.SPA/Pages/RecurrencyAdjustment.razor.cs @@ -21,6 +21,8 @@ public partial class RecurrencyAdjustment : ComponentBase public bool isNew { get; set; } + public bool OperationRunning { get; set; } = false; + protected override async Task OnInitializedAsync() { var existentAdjustment = await this.savingsAPI.GetRecurrencyAdjustementByIDRecurrencyAndDate(materializedItem.RecurrentMoneyItemID.Value, materializedItem.Date.Date); @@ -38,22 +40,34 @@ protected override async Task OnInitializedAsync() private async void OnValidSubmit() { - if (!adjustement.RecurrencyNewDate.HasValue && !adjustement.RecurrencyNewAmount.HasValue && !isNew) - { - await this.savingsAPI.DeleteRecurrencyAdjustment(adjustement.ID); - } - else - { - if (isNew) - { - await this.savingsAPI.InsertRecurrencyAdjustment(adjustement); - } - else - { - await this.savingsAPI.EditRecurrencyAdjustment(adjustement.ID, adjustement); - } + try + { + OperationRunning = true; + if (!adjustement.RecurrencyNewDate.HasValue && !adjustement.RecurrencyNewAmount.HasValue && !isNew) + { + await this.savingsAPI.DeleteRecurrencyAdjustment(adjustement.ID); + } + else + { + if (isNew) + { + await this.savingsAPI.InsertRecurrencyAdjustment(adjustement); + } + else + { + await this.savingsAPI.EditRecurrencyAdjustment(adjustement.ID, adjustement); + } + } + this.dialogService.Close(true); + } + catch (Exception) + { + throw; + } + finally + { + OperationRunning = false; } - this.dialogService.Close(true); } } diff --git a/src/Savings.SPA/Pages/RecurrentItemEdit.razor b/src/Savings.SPA/Pages/RecurrentItemEdit.razor index ab359b6..edde35e 100644 --- a/src/Savings.SPA/Pages/RecurrentItemEdit.razor +++ b/src/Savings.SPA/Pages/RecurrentItemEdit.razor @@ -81,15 +81,17 @@
- - @if (!isNew) { - + }
diff --git a/src/Savings.SPA/Pages/RecurrentItemEdit.razor.cs b/src/Savings.SPA/Pages/RecurrentItemEdit.razor.cs index 63efe7c..e3421f2 100644 --- a/src/Savings.SPA/Pages/RecurrentItemEdit.razor.cs +++ b/src/Savings.SPA/Pages/RecurrentItemEdit.razor.cs @@ -35,6 +35,8 @@ public partial class RecurrentItemEdit : ComponentBase InputNumber amountInputNumber; + public bool OperationRunning { get; set; } = false; + protected override async void OnAfterRender(bool firstRender) { @@ -71,6 +73,7 @@ async Task Delete() { try { + OperationRunning = true; var res = await dialogService.Confirm("Are you sure you want delete?", "Delete recurrent item", new ConfirmOptions() { OkButtonText = "Yes", CancelButtonText = "No" }); if (res.HasValue && res.Value) { @@ -82,6 +85,10 @@ async Task Delete() { notificationService.Notify(NotificationSeverity.Error, "Error", ex.Message); } + finally + { + OperationRunning = false; + } } @@ -104,6 +111,7 @@ private async void OnValidSubmit() { try { + OperationRunning = true; if (!ValidateData()) return; if (isNew) { @@ -119,6 +127,10 @@ private async void OnValidSubmit() { throw; } + finally + { + OperationRunning = false; + } } }