Refactor. Add data layer
This commit is contained in:
1 parent
3b7e4e6ec5
commit
b6b794f0b4
82 files changed
+2930
-2811
No files matched your search
@@ -0,0 +1,43 @@
|
||||
using BudgetApp.Data.Entities;
|
||||
|
||||
namespace BudgetApp.Components.Layout;
|
||||
|
||||
public partial class NavMenu
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user