| | 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() |
| 0 | 54 | | { |
| | 55 | | // Subscribe to the event |
| 0 | 56 | | NavigationManager.LocationChanged += LocationChanged; |
| | 57 | |
|
| 0 | 58 | | var name = await localStorage.GetItemAsync<string>(Constants.LOCAL_STORAGE_TAB); |
| 0 | 59 | | if (!string.IsNullOrEmpty(name)) |
| 0 | 60 | | { |
| 0 | 61 | | NavigationManager.NavigateTo(name); // Navigate |
| 0 | 62 | | } |
| | 63 | |
|
| 0 | 64 | | base.OnInitialized(); |
| 0 | 65 | | } |
| | 66 | |
|
| | 67 | | async void LocationChanged(object sender, LocationChangedEventArgs e) |
| 0 | 68 | | { |
| | 69 | | // string navigationMethod = e.IsNavigationIntercepted ? "HTML" : "code"; |
| | 70 | | // System.Diagnostics.Debug.WriteLine($"Notified of navigation via {navigationMethod} to {e.Location}"); |
| | 71 | |
|
| 0 | 72 | | Uri uri = new Uri(e.Location); |
| 0 | 73 | | string pathName = uri.AbsolutePath; |
| 0 | 74 | | var path = pathName.Split(new []{ "/" }, StringSplitOptions.RemoveEmptyEntries); |
| 0 | 75 | | if (path.Length != 0) |
| 0 | 76 | | await localStorage.SetItemAsync(Constants.LOCAL_STORAGE_TAB, path[^1]); |
| 0 | 77 | | } |
| | 78 | |
|
| | 79 | | void IDisposable.Dispose() |
| 0 | 80 | | { |
| | 81 | | // Unsubscribe from the event when our component is disposed |
| 0 | 82 | | NavigationManager.LocationChanged -= LocationChanged; |
| 0 | 83 | | } |
| | 84 | | } |