Files
2026-03-06 11:05:01 +00:00

43 lines
1.2 KiB
C#

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");
}
}