| | 1 | | @using Syki.Front.Features.Cross.GetUserNotifications |
| | 2 | |
|
| | 3 | | @namespace Syki.Front.Shared |
| | 4 | |
|
| | 5 | | @inherits LayoutComponentBase |
| | 6 | |
|
| | 7 | | <MudPopoverProvider /> |
| | 8 | | <MudSnackbarProvider /> |
| | 9 | | <MudThemeProvider IsDarkMode="@_isDark" /> |
| | 10 | | <MudDialogProvider CloseOnEscapeKey="true" CloseButton="true" /> |
| | 11 | |
|
| | 12 | | <AuthorizeView> |
| | 13 | | <Authorized> |
| | 14 | | <MudLayout> |
| | 15 | | <MudAppBar Elevation="0" Dense="true" ToolBarClass="pl-1 pr-1"> |
| 0 | 16 | | @if (_breakpoint != Breakpoint.Xs) |
| | 17 | | { |
| | 18 | | <MudIconButton Class="mr-2" OnClick="@ToggleLeftOpen" Icon="@Icons.Material.Filled.Menu" Color="Colo |
| | 19 | | } |
| | 20 | | <HomeButton /> |
| | 21 | | <MudSpacer /> |
| | 22 | | <AuthorizeView Roles="Teacher, Student" Context="authContext"> |
| | 23 | | <NotificationsIconButton /> |
| | 24 | | </AuthorizeView> |
| | 25 | | <ThemeIconButton @bind-IsDark="@_isDark" OnClick="@ChangeTheme" /> |
| | 26 | | <MudIconButton OnClick="@ToggleRightOpen" Icon="@Icons.Material.Filled.Settings" Color="Color.Inherit" / |
| | 27 | | </MudAppBar> |
| | 28 | | <MudDrawer @bind-Open="@_leftOpen" ClipMode="DrawerClipMode.Always" Elevation="2" Width="160px"> |
| | 29 | | <NavMenu /> |
| | 30 | | </MudDrawer> |
| | 31 | | <MudDrawer Anchor="Anchor.Right" @bind-Open="@_rightOpen" ClipMode="DrawerClipMode.Always" Variant="DrawerVa |
| | 32 | | <SettingsMenu OnLogoutClick="@Logout" /> |
| | 33 | | </MudDrawer> |
| | 34 | | <MudMainContent Class="pb-12"> |
| | 35 | | @Body |
| 0 | 36 | | @if (_breakpoint == Breakpoint.Xs) |
| | 37 | | { |
| | 38 | | <MudFab OnClick="@ToggleLeftOpen" Size="@Size.Large" Style="position:fixed; bottom:15px; right:25px; |
| | 39 | | } |
| | 40 | | </MudMainContent> |
| | 41 | | </MudLayout> |
| | 42 | | </Authorized> |
| | 43 | | <NotAuthorized> |
| 0 | 44 | | @if (Nav.Uri.EndsWith("/") || Nav.Uri.ToLower().Contains("register") || Nav.Uri.ToLower().Contains("login") || N |
| | 45 | | { |
| | 46 | | <MudAppBar Elevation="1" Dense="true"> |
| | 47 | | <MudStack Row="true" Class="d-flex justify-space-around flex-grow-1"> |
| | 48 | | <HomeButton /> |
| | 49 | | <MudSpacer /> |
| | 50 | | <ThemeIconButton @bind-IsDark="@_isDark" OnClick="@ChangeTheme" /> |
| | 51 | | <LoginButton /> |
| | 52 | | </MudStack> |
| | 53 | | </MudAppBar> |
| | 54 | | <CascadingValue Name="IsDarkTheme" Value="@_isDark"> |
| | 55 | | <MudMainContent> |
| | 56 | | @Body |
| | 57 | | </MudMainContent> |
| | 58 | | </CascadingValue> |
| | 59 | | } |
| | 60 | | else |
| | 61 | | { |
| | 62 | | <SykiRedirect /> |
| | 63 | | } |
| | 64 | | </NotAuthorized> |
| | 65 | | </AuthorizeView> |
| | 66 | |
|
| | 67 | |
|
| | 68 | | @inject NavigationManager Nav |
| | 69 | | @inject ILocalStorageService LocalStorage |
| | 70 | | @inject SykiAuthStateProvider AuthStateProvider |
| | 71 | | @inject IBrowserViewportService BrowserViewportService |
| | 72 | |
|
| | 73 | | @code |
| | 74 | | { |
| | 75 | | [CascadingParameter] |
| 0 | 76 | | public Task<AuthenticationState> AuthState { get; set; } |
| | 77 | |
|
| 0 | 78 | | private bool _isDark = true; |
| 0 | 79 | | private bool _leftOpen = true; |
| | 80 | | private bool _rightOpen = false; |
| | 81 | | private Breakpoint _breakpoint; |
| | 82 | |
|
| | 83 | | private void ToggleLeftOpen() |
| | 84 | | { |
| 0 | 85 | | _leftOpen = !_leftOpen; |
| 0 | 86 | | } |
| | 87 | |
|
| | 88 | | private void ToggleRightOpen() |
| | 89 | | { |
| 0 | 90 | | _rightOpen = !_rightOpen; |
| 0 | 91 | | } |
| | 92 | |
|
| | 93 | | protected override async Task OnInitializedAsync() |
| | 94 | | { |
| 0 | 95 | | _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 96 | | var isDark = await LocalStorage.GetItemAsync("IsDark"); |
| 0 | 97 | | _isDark = isDark == null || bool.Parse(isDark); |
| 0 | 98 | | } |
| | 99 | |
|
| | 100 | | protected override async Task OnAfterRenderAsync(bool firstRender) |
| | 101 | | { |
| 0 | 102 | | await base.OnAfterRenderAsync(firstRender); |
| | 103 | |
|
| 0 | 104 | | } |
| | 105 | |
|
| | 106 | | private async Task ChangeTheme() |
| | 107 | | { |
| 0 | 108 | | _isDark = !_isDark; |
| 0 | 109 | | await LocalStorage.SetItemAsync("IsDark", _isDark.ToString()); |
| 0 | 110 | | } |
| | 111 | |
|
| | 112 | | private async Task Logout() |
| | 113 | | { |
| 0 | 114 | | _rightOpen = false; |
| 0 | 115 | | await LocalStorage.RemoveItemAsync("AccessToken"); |
| 0 | 116 | | AuthStateProvider.MarkUserAsLoggedOut(); |
| 0 | 117 | | Nav.NavigateTo("/"); |
| 0 | 118 | | } |
| | 119 | | } |