From dd5c505f790c18364e79851e9c170fa3cdffab09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Sun, 16 May 2021 09:12:41 +0200 Subject: [PATCH] #343 - Handle income created / delete events on Summary. --- src/Money.Blazor.Host/Pages/Summary.razor.cs | 39 ++++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/Money.Blazor.Host/Pages/Summary.razor.cs b/src/Money.Blazor.Host/Pages/Summary.razor.cs index e2719f04..76882a94 100644 --- a/src/Money.Blazor.Host/Pages/Summary.razor.cs +++ b/src/Money.Blazor.Host/Pages/Summary.razor.cs @@ -30,7 +30,9 @@ public partial class Summary : IEventHandler, IEventHandler, IEventHandler, - IEventHandler + IEventHandler, + IEventHandler, + IEventHandler { private CurrencyFormatter formatter; @@ -118,11 +120,7 @@ protected async Task LoadSelectedPeriodAsync() { Categories = await Queries.QueryAsync(CreateCategoriesQuery(SelectedPeriod)); - var incomeQuery = CreateIncomeTotalQuery(SelectedPeriod); - if (incomeQuery != null) - IncomeTotal = await Queries.QueryAsync(CreateIncomeTotalQuery(SelectedPeriod)); - else - IncomeTotal = null; + await LoadIncomeTotalAsync(); ExpenseTotal = await Queries.QueryAsync(CreateExpenseTotalQuery(SelectedPeriod)); } @@ -136,6 +134,15 @@ protected async Task LoadSelectedPeriodAsync() } } + private async Task LoadIncomeTotalAsync() + { + var incomeQuery = CreateIncomeTotalQuery(SelectedPeriod); + if (incomeQuery != null) + IncomeTotal = await Queries.QueryAsync(CreateIncomeTotalQuery(SelectedPeriod)); + else + IncomeTotal = null; + } + protected virtual IQuery CreateIncomeTotalQuery(T item) => null; @@ -203,7 +210,9 @@ private void BindEvents() .Add(this) .Add(this) .Add(this) - .Add(this); + .Add(this) + .Add(this) + .Add(this); } private void UnBindEvents() @@ -213,7 +222,9 @@ private void UnBindEvents() .Remove(this) .Remove(this) .Remove(this) - .Remove(this); + .Remove(this) + .Remove(this) + .Remove(this); } Task IEventHandler.HandleAsync(OutcomeCreated payload) @@ -247,6 +258,18 @@ Task IEventHandler.HandleAsync(PulledToRefresh payload) return Task.CompletedTask; } + async Task IEventHandler.HandleAsync(IncomeCreated payload) + { + await LoadIncomeTotalAsync(); + StateHasChanged(); + } + + async Task IEventHandler.HandleAsync(IncomeDeleted payload) + { + await LoadIncomeTotalAsync(); + StateHasChanged(); + } + private async void OnMonthUpdatedEvent(DateTime changed) { if (Periods != null && !IsContained(changed))