Skip to content

Commit

Permalink
Disable buttons when operation running
Browse files Browse the repository at this point in the history
  • Loading branch information
liguori committed Feb 3, 2024
1 parent 6f4dcd9 commit 0cf9356
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 28 deletions.
8 changes: 5 additions & 3 deletions src/Savings.SPA/Pages/FixedItemEdit.razor
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,17 @@
<ValidationMessage For="@(() => fixedItemToEdit.CategoryID)" />
</div>
<div class="text-center">
<button type="submit" class="btn btn-success">
<button type="submit" class="btn btn-success" disabled="@OperationRunning">
<span class="oi oi-circle-check" aria-hidden="true"></span>SAVE
</button>
<button type="button" class="btn btn-warning" @onclick="@(() => { this.dialogService.Close(false); })">
<button type="button" class="btn btn-warning" @onclick="@(() => { this.dialogService.Close(false); })" disabled="@OperationRunning">
<span class="oi oi-reload" aria-hidden="true"></span>CANCEL
</button>
@if (!isNew)
{
<button type="button" class="btn btn-danger" @onclick="@(()=>Delete())"><span class="oi oi-trash" aria-hidden="true"></span></button>
<button type="button" class="btn btn-danger" @onclick="@(()=>Delete())" disabled="@OperationRunning">
<span class="oi oi-trash" aria-hidden="true"></span>
</button>
}
</div>
</EditForm>
29 changes: 24 additions & 5 deletions src/Savings.SPA/Pages/FixedItemEdit.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<decimal?> amountInputNumber;
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -87,6 +101,7 @@ private async void OnValidSubmit()
{
try
{
OperationRunning = true;
if (!ValidateData()) return;
if (Incoming)
{
Expand All @@ -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;
}

}

Expand Down
4 changes: 2 additions & 2 deletions src/Savings.SPA/Pages/RecurrencyAdjustment.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
</div>
</div>
<div class="text-center">
<button type="submit" class="btn btn-success">
<button type="submit" class="btn btn-success" disabled="@OperationRunning">
<span class="oi oi-circle-check" aria-hidden="true"></span>SAVE
</button>
<button type="button" class="btn btn-warning" @onclick="@(() => { this.dialogService.Close(false); })">
<button type="button" class="btn btn-warning" @onclick="@(() => { this.dialogService.Close(false); })" disabled="@OperationRunning">
<span class="oi oi-reload" aria-hidden="true"></span>CANCEL
</button>
</div>
Expand Down
44 changes: 29 additions & 15 deletions src/Savings.SPA/Pages/RecurrencyAdjustment.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

}
Expand Down
8 changes: 5 additions & 3 deletions src/Savings.SPA/Pages/RecurrentItemEdit.razor
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,17 @@
<ValidationMessage For="@(() => recurrentItemToEdit.CategoryID)" />
</div>
<div class="text-center">
<button type="submit" class="btn btn-success">
<button type="submit" class="btn btn-success" disabled="@OperationRunning">
<span class="oi oi-circle-check" aria-hidden="true"></span>SAVE
</button>
<button type="button" class="btn btn-warning" @onclick="@(() => { this.dialogService.Close(false); })">
<button type="button" class="btn btn-warning" @onclick="@(() => { this.dialogService.Close(false); })" disabled="@OperationRunning">
<span class="oi oi-reload" aria-hidden="true"></span>CANCEL
</button>
@if (!isNew)
{
<button type="button" class="btn btn-danger" @onclick="@(()=>Delete())"><span class="oi oi-trash" aria-hidden="true"></span></button>
<button type="button" class="btn btn-danger" @onclick="@(()=>Delete())" disabled="@OperationRunning">
<span class="oi oi-trash" aria-hidden="true"></span>
</button>
}
</div>
</EditForm>
12 changes: 12 additions & 0 deletions src/Savings.SPA/Pages/RecurrentItemEdit.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public partial class RecurrentItemEdit : ComponentBase

InputNumber<decimal> amountInputNumber;

public bool OperationRunning { get; set; } = false;


protected override async void OnAfterRender(bool firstRender)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -82,6 +85,10 @@ async Task Delete()
{
notificationService.Notify(NotificationSeverity.Error, "Error", ex.Message);
}
finally
{
OperationRunning = false;
}
}


Expand All @@ -104,6 +111,7 @@ private async void OnValidSubmit()
{
try
{
OperationRunning = true;
if (!ValidateData()) return;
if (isNew)
{
Expand All @@ -119,6 +127,10 @@ private async void OnValidSubmit()
{
throw;
}
finally
{
OperationRunning = false;
}

}
}
Expand Down

0 comments on commit 0cf9356

Please sign in to comment.