automatically rerenders orderlist when orders are balanced

This commit is contained in:
Tea 2024-04-10 15:44:23 +02:00
parent 02666f9d76
commit c53289b218
2 changed files with 14 additions and 0 deletions

View file

@ -4,6 +4,7 @@
@inject PizzaDBService PizzaDBService
@inject Microsoft.AspNetCore.Components.NavigationManager navigationManager
@inject GlobalStuffService GlobalStuffService
@rendermode InteractiveServer
@attribute [StreamRendering]
<PageTitle>Pizza List</PageTitle>
@ -118,4 +119,13 @@
{
navigationManager.NavigateTo($"/order/edit/{id}");
}
protected override void OnInitialized()
{
EventHandler Reload = async (sender, eventArgs) =>
{
await InvokeAsync(StateHasChanged);
};
PizzaDBService.OnBalanced += Reload;
}
}

View file

@ -32,6 +32,8 @@ namespace PizzaBot.Services
private PizzaRequestNameEqualityComparer _reqNameEqualityComparer = new PizzaRequestNameEqualityComparer();
private Random _rnd = new Random();
public event EventHandler OnBalanced;
public PizzaDBService(PizzaContext context, PizzaBalancingService balancingService, GlobalStuffService globalStuffService)
{
_context = context;
@ -230,6 +232,8 @@ namespace PizzaBot.Services
_globalStuffService.TotalCost = balancingResult.totalCost;
_globalStuffService.ShouldBalance = false;
OnBalanced(this, null);
}
public bool DeleteAllOrders(string passPhrase)