summary refs log tree commit diff
path: root/testFrontend/SafeNSound.Demo/Pages/User.razor
diff options
context:
space:
mode:
Diffstat (limited to 'testFrontend/SafeNSound.Demo/Pages/User.razor')
-rw-r--r--testFrontend/SafeNSound.Demo/Pages/User.razor46
1 files changed, 44 insertions, 2 deletions
diff --git a/testFrontend/SafeNSound.Demo/Pages/User.razor b/testFrontend/SafeNSound.Demo/Pages/User.razor

index cdffbe3..cfbfa53 100644 --- a/testFrontend/SafeNSound.Demo/Pages/User.razor +++ b/testFrontend/SafeNSound.Demo/Pages/User.razor
@@ -16,6 +16,30 @@ <LinkButton Color="#FF0000" OnClick="@(() => RaiseAlarm(null))">Clear</LinkButton> </span> <br/> + + <span>Budget: @Math.Round(Budget.Amount, 2)</span><br/> + + <span> + Spend + <FancyTextBox Value="@ToSpend.Amount.ToString()" ValueChanged="s => ToSpend.Amount = double.Parse(s)"/> + EUR at + <FancyTextBox @bind-Value="@ToSpend.Venue"/> + for + <FancyTextBox @bind-Value="@ToSpend.Reason"/> + <LinkButton OnClick="@(() => SpendBudget(ToSpend))">Spend</LinkButton> + </span><br/> + + <i>Spend history is comming soon!</i> + @* oops, forgot to use the DTO for getting own budget... *@ + @* @foreach(var history in Budget.History) { *@ + @* <div> *@ + @* <span>@history.CreatedAt!.Value.ToLocalTime()</span> - *@ + @* <span>@history.Amount EUR</span> - *@ + @* <span>@history.Reason</span> - *@ + @* <span>@history.Venue</span> *@ + @* </div> *@ + @* } *@ + } @if (Alarm != null) { @@ -38,16 +62,22 @@ private WhoAmI WhoAmI { get; set; } = null!; private AlarmDto? Alarm { get; set; } = null!; + private BudgetHistoryEntry ToSpend { get; set; } = new() { + Amount = 0, + Reason = string.Empty, + Venue = string.Empty + }; protected override async Task OnInitializedAsync() { WhoAmI = await App.UserClient.WhoAmI(); - _isInitialized = true; _ = PollAlarm(); + Budget = await App.UserClient.GetBudget(); NavigationManager.LocationChanged += (sender, args) => { if (args.Location != NavigationManager.Uri) { - _running = false; // Stop polling when navigating away + _running = false; } }; + _isInitialized = true; } private async Task PollAlarm() { @@ -57,11 +87,19 @@ Alarm = newAlarm; StateHasChanged(); } + + var newBudget = await App.UserClient.GetBudget(); + if (Math.Abs(Budget.Amount - newBudget.Amount) > 0.01) { + Budget = newBudget; + StateHasChanged(); + } await Task.Delay(1000); } } + public CurrentBalance Budget { get; set; } + private async Task RaiseAlarm(string? reason) { if (string.IsNullOrWhiteSpace(reason)) await App.UserClient.DeleteAlarm(); @@ -80,4 +118,8 @@ ~User() => ReleaseUnmanagedResources(); + private async Task SpendBudget(BudgetHistoryEntry toSpend) { + await App.UserClient.SpendBudget(toSpend); + } + } \ No newline at end of file