Refactor. Add data layer
This commit is contained in:
1 parent
3b7e4e6ec5
commit
b6b794f0b4
82 files changed
+2930
-2811
No files matched your search
@@ -1,4 +1,4 @@
|
||||
@inject AccountService AccountService
|
||||
@inject IAccountRepository AccountService
|
||||
@inject AuthenticationStateProvider AuthStateProvider
|
||||
@inject AppState AppState
|
||||
@inject NavigationManager Navigation
|
||||
@@ -70,11 +70,11 @@
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@if (accounts is not null && accounts.Count > 0)
|
||||
@if (_accounts is not null && _accounts.Count > 0)
|
||||
{
|
||||
<div class="nav-balances px-3">
|
||||
<div class="balances-header">Balances</div>
|
||||
@foreach (var account in accounts)
|
||||
@foreach (var account in _accounts)
|
||||
{
|
||||
<div class="balance-item" style="cursor: pointer;" title="Click to manage accounts" @onclick="NavigateToAccounts">
|
||||
<div class="balance-color" style="background-color: @account.Color;"></div>
|
||||
@@ -88,44 +88,4 @@
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private List<Account>? accounts;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
AppState.OnAccountsChanged += HandleAccountsChanged;
|
||||
|
||||
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
|
||||
var userId = authState.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
if (userId is not null)
|
||||
{
|
||||
accounts = await AccountService.GetAccountsAsync(userId);
|
||||
}
|
||||
}
|
||||
|
||||
private async void HandleAccountsChanged()
|
||||
{
|
||||
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
|
||||
var userId = authState.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
if (userId is not null)
|
||||
{
|
||||
accounts = await AccountService.GetAccountsAsync(userId);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
AppState.OnAccountsChanged -= HandleAccountsChanged;
|
||||
}
|
||||
|
||||
private void NavigateToAccounts()
|
||||
{
|
||||
Navigation.NavigateTo("accounts");
|
||||
}
|
||||
}
|
||||
|
||||
</div>
|
||||
Reference in new issue
Block a user