< Summary

Information
Class: Syki.Front.Shared.MainLayout
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Shared/MainLayout.razor
Tag: 22_11348620282
Line coverage
0%
Covered lines: 0
Uncovered lines: 24
Coverable lines: 24
Total lines: 119
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 14
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_AuthState()100%210%
.ctor()100%210%
ToggleLeftOpen()100%210%
ToggleRightOpen()100%210%
OnInitializedAsync()0%620%
OnAfterRenderAsync()100%210%
ChangeTheme()100%210%
Logout()100%210%

File(s)

/home/runner/work/syki/syki/Front/Shared/MainLayout.razor

#LineLine coverage
 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">
 016                @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
 036                @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>
 044        @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]
 076    public Task<AuthenticationState> AuthState { get; set; }
 77
 078    private bool _isDark = true;
 079    private bool _leftOpen = true;
 80    private bool _rightOpen = false;
 81    private Breakpoint _breakpoint;
 82
 83    private void ToggleLeftOpen()
 84    {
 085        _leftOpen = !_leftOpen;
 086    }
 87
 88    private void ToggleRightOpen()
 89    {
 090        _rightOpen = !_rightOpen;
 091    }
 92
 93    protected override async Task OnInitializedAsync()
 94    {
 095        _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync();
 096        var isDark = await LocalStorage.GetItemAsync("IsDark");
 097        _isDark = isDark == null || bool.Parse(isDark);
 098    }
 99
 100    protected override async Task OnAfterRenderAsync(bool firstRender)
 101    {
 0102        await base.OnAfterRenderAsync(firstRender);
 103
 0104    }
 105
 106    private async Task ChangeTheme()
 107    {
 0108        _isDark = !_isDark;
 0109        await LocalStorage.SetItemAsync("IsDark", _isDark.ToString());
 0110    }
 111
 112    private async Task Logout()
 113    {
 0114        _rightOpen = false;
 0115        await LocalStorage.RemoveItemAsync("AccessToken");
 0116        AuthStateProvider.MarkUserAsLoggedOut();
 0117        Nav.NavigateTo("/");
 0118    }
 119}