2025-10-07 23:40:43 +03:30
|
|
|
using Blazored.LocalStorage;
|
|
|
|
|
using FrontOffice.Main.Utilities;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
2025-09-28 01:28:44 +03:30
|
|
|
using Microsoft.JSInterop;
|
|
|
|
|
using MudBlazor;
|
2025-10-20 21:17:53 +03:30
|
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
2025-09-28 01:28:44 +03:30
|
|
|
|
|
|
|
|
namespace FrontOffice.Main.Shared;
|
|
|
|
|
public partial class MainLayout
|
|
|
|
|
{
|
2025-10-07 23:40:43 +03:30
|
|
|
private const string TokenStorageKey = "auth:token";
|
|
|
|
|
|
2025-09-28 01:28:44 +03:30
|
|
|
private MudThemeProvider _mudThemeProvider;
|
2025-09-28 10:55:21 +03:30
|
|
|
private bool _isDark;
|
|
|
|
|
private bool _drawerOpen;
|
2025-10-07 23:40:43 +03:30
|
|
|
private bool _isAuthenticated;
|
2025-09-28 10:55:21 +03:30
|
|
|
private string? _email;
|
|
|
|
|
|
2025-10-07 23:40:43 +03:30
|
|
|
[Inject] private ILocalStorageService LocalStorage { get; set; } = default!;
|
2025-10-20 21:17:53 +03:30
|
|
|
[Inject] private AuthService AuthService { get; set; } = default!;
|
|
|
|
|
[Inject] private AuthDialogService AuthDialogService { get; set; } = default!;
|
2025-10-07 23:40:43 +03:30
|
|
|
|
2025-09-28 10:55:21 +03:30
|
|
|
private void ToggleTheme() => _isDark = !_isDark;
|
|
|
|
|
private void ToggleDrawer() => _drawerOpen = !_drawerOpen;
|
2025-09-28 01:28:44 +03:30
|
|
|
private async void Back()
|
|
|
|
|
{
|
|
|
|
|
await JSRuntime.InvokeVoidAsync("history.back");
|
|
|
|
|
}
|
2025-10-07 23:40:43 +03:30
|
|
|
|
2025-10-07 00:39:38 +03:30
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
if (firstRender)
|
|
|
|
|
{
|
|
|
|
|
await JSRuntime.InvokeVoidAsync("changeNavBgOnBodyScroll", "top", null, 1);
|
2025-10-07 23:40:43 +03:30
|
|
|
await CheckAuthStatus();
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task CheckAuthStatus()
|
|
|
|
|
{
|
2025-10-20 21:17:53 +03:30
|
|
|
_isAuthenticated = await AuthService.IsAuthenticatedAsync();
|
2025-10-07 23:40:43 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OpenAuthDialog()
|
|
|
|
|
{
|
2025-10-20 21:17:53 +03:30
|
|
|
await AuthDialogService.ShowAuthDialogAsync();
|
|
|
|
|
await CheckAuthStatus();
|
|
|
|
|
if (_isAuthenticated)
|
2025-10-07 23:40:43 +03:30
|
|
|
{
|
2025-10-20 20:55:55 +03:30
|
|
|
Snackbar.Add(GlobalConstants.SuccessMsg, Severity.Success);
|
2025-10-07 00:39:38 +03:30
|
|
|
}
|
2025-11-17 00:17:10 +03:30
|
|
|
|
2025-10-20 21:17:53 +03:30
|
|
|
StateHasChanged();
|
2025-11-17 00:17:10 +03:30
|
|
|
Navigation.NavigateTo(RouteConstants.Main.MainPage);
|
2025-10-07 00:39:38 +03:30
|
|
|
}
|
2025-10-07 23:40:43 +03:30
|
|
|
|
|
|
|
|
private void NavigateToProfile()
|
|
|
|
|
{
|
|
|
|
|
Navigation.NavigateTo(RouteConstants.Profile.Index);
|
|
|
|
|
}
|
2025-10-20 21:02:13 +03:30
|
|
|
|
|
|
|
|
private async Task Logout()
|
|
|
|
|
{
|
2025-10-20 21:17:53 +03:30
|
|
|
await AuthService.LogoutAsync();
|
2025-10-20 21:02:13 +03:30
|
|
|
_isAuthenticated = false;
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
2025-09-28 01:28:44 +03:30
|
|
|
}
|