This commit is contained in:
MeysamMoghaddam
2025-10-07 23:40:43 +03:30
parent 47152ab05e
commit 45999329e7
6 changed files with 629 additions and 66 deletions

View File

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