u
This commit is contained in:
@@ -1,26 +1,59 @@
|
||||
using Blazored.LocalStorage;
|
||||
using FrontOffice.Main.Utilities;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
using MudBlazor;
|
||||
|
||||
namespace FrontOffice.Main.Shared;
|
||||
public partial class MainLayout
|
||||
{
|
||||
private const string TokenStorageKey = "auth:token";
|
||||
|
||||
private MudThemeProvider _mudThemeProvider;
|
||||
private bool _isDark;
|
||||
private bool _drawerOpen;
|
||||
private bool _isAuthenticated;
|
||||
private string? _email;
|
||||
|
||||
[Inject] private ILocalStorageService LocalStorage { get; set; } = default!;
|
||||
|
||||
private void ToggleTheme() => _isDark = !_isDark;
|
||||
private void ToggleDrawer() => _drawerOpen = !_drawerOpen;
|
||||
private async void Back()
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("history.back");
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("changeNavBgOnBodyScroll", "top", null, 1);
|
||||
await CheckAuthStatus();
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CheckAuthStatus()
|
||||
{
|
||||
var token = await LocalStorage.GetItemAsync<string>(TokenStorageKey);
|
||||
_isAuthenticated = !string.IsNullOrWhiteSpace(token);
|
||||
}
|
||||
|
||||
private async Task OpenAuthDialog()
|
||||
{
|
||||
var dialog = await DialogService.ShowAsync<AuthDialog>("ورود به حساب کاربری");
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (!result.Canceled)
|
||||
{
|
||||
await CheckAuthStatus();
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void NavigateToProfile()
|
||||
{
|
||||
Navigation.NavigateTo(RouteConstants.Profile.Index);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user