< Summary

Information
Class: Utility.Shared.MainLayout
Assembly: Utility
File(s): /home/runner/work/Utility-Blazor/Utility-Blazor/src/Utility/Shared/MainLayout.razor
Tag: 254_14892742572
Line coverage
0%
Covered lines: 0
Uncovered lines: 19
Coverable lines: 19
Total lines: 84
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
OnInitializedAsync()0%620%
LocationChanged()0%620%
System.IDisposable.Dispose()100%210%

File(s)

/home/runner/work/Utility-Blazor/Utility-Blazor/src/Utility/Shared/MainLayout.razor

#LineLine coverage
 1@implements IDisposable
 2@inherits LayoutComponentBase
 3
 4@inject Blazored.LocalStorage.ILocalStorageService localStorage
 5@inject NavigationManager NavigationManager
 6
 7<FluentLayout>
 8    <FluentHeader>
 9        <div>
 10            Utility
 11        </div>
 12        <FluentSpacer />
 13        <div class="settings">
 14            <SiteSettings />
 15        </div>
 16    </FluentHeader>
 17    <FluentStack Class="main" Orientation="Orientation.Horizontal" Width="100%">
 18        <NavMenu />
 19        <FluentBodyContent Class="body-content">
 20            <ErrorBoundary>
 21                <ChildContent>
 22                    <div class="content">
 23                        @Body
 24                    </div>
 25                </ChildContent>
 26                <ErrorContent Context="ex">
 27                    <div class="blazor-error-boundary">@ex.Message</div>
 28                </ErrorContent>
 29            </ErrorBoundary>
 30            <FluentDialogProvider />
 31        </FluentBodyContent>
 32    </FluentStack>
 33    <FluentFooter>
 34        <div class="link1">
 35            <a href="https://alexhedley.com/Utility-Documentation/" target="_blank">Documentation</a>
 36        </div>
 37        <FluentSpacer />
 38        <div class="link3">
 39            <a href="https://alexhedley.github.io/Utility-Blazor/" target="_blank"><i class="fab fa-github"></i> Code</a
 40        </div>
 41        <FluentSpacer />
 42        <div class="link2">
 43            <a href="https://alexhedley.com/Utility/" target="_blank">About</a>
 44        </div>
 45    </FluentFooter>
 46</FluentLayout>
 47
 48
 49
 50@code {
 51    // Detecting navigation events
 52    // https://blazor-university.com/routing/detecting-navigation-events/
 53    protected override async Task OnInitializedAsync()
 054    {
 55        // Subscribe to the event
 056        NavigationManager.LocationChanged += LocationChanged;
 57
 058        var name = await localStorage.GetItemAsync<string>(Constants.LOCAL_STORAGE_TAB);
 059        if (!string.IsNullOrEmpty(name))
 060        {
 061            NavigationManager.NavigateTo(name); // Navigate
 062        }
 63
 064        base.OnInitialized();
 065    }
 66
 67    async void LocationChanged(object sender, LocationChangedEventArgs e)
 068    {
 69        // string navigationMethod = e.IsNavigationIntercepted ? "HTML" : "code";
 70        // System.Diagnostics.Debug.WriteLine($"Notified of navigation via {navigationMethod} to {e.Location}");
 71
 072        Uri uri = new Uri(e.Location);
 073        string pathName = uri.AbsolutePath;
 074        var path = pathName.Split(new []{ "/" }, StringSplitOptions.RemoveEmptyEntries);
 075        if (path.Length != 0)
 076            await localStorage.SetItemAsync(Constants.LOCAL_STORAGE_TAB, path[^1]);
 077    }
 78
 79    void IDisposable.Dispose()
 080    {
 81        // Unsubscribe from the event when our component is disposed
 082        NavigationManager.LocationChanged -= LocationChanged;
 083    }
 84}