Skip to content

Commit

Permalink
Applied some minor refactoring to the AppLayout.razor
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram1903 committed Apr 8, 2024
1 parent 45b086e commit cb91434
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions src/Server.UI/Components/Shared/Layout/AppLayout.razor
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
@using Severity = Severity
@using Toolbelt.Blazor.HotKeys2
@using CleanArchitecture.Blazor.Server.UI.Services.UserPreferences
@using CleanArchitecture.Blazor.Server.UI.Constants
@layout MainLayout
@layout MainLayout
@inherits LayoutComponentBase

@inject LayoutService LayoutService
@inject HotKeys HotKeys
@inject IStringLocalizer<SharedResource> L
<MudLayout>
<AuthorizeView>
<NotAuthorized>
<RedirectToLogin />
<RedirectToLogin/>
</NotAuthorized>
<Authorized>
<HeaderMenu NavigationMenuDrawerOpen="_navigationMenuDrawerOpen"
Expand All @@ -20,17 +14,17 @@
ToggleNavigationMenuDrawer="ToggleNavigationMenuDrawer"
RightToLeft="@LayoutService.IsRTL"
RightToLeftToggle="LayoutService.ToggleRightToLeft"
OnSettingClick="@(() => _themingDrawerOpen = true)" />
OnSettingClick="@(() => _themingDrawerOpen = true)"/>
<NavigationMenu DrawerOpen="_navigationMenuDrawerOpen" Roles="@_userProfile?.AssignedRoles"
DrawerOpenChanged="NavigationMenuDrawerOpenChangedHandler" />
DrawerOpenChanged="NavigationMenuDrawerOpenChangedHandler"/>
<ThemesMenu ThemingDrawerOpen="_themingDrawerOpen"
ThemingDrawerOpenChanged="ThemingDrawerOpenChangedHandler"
UserPreferences="@LayoutService.UserPreferences"
UserPreferencesChanged="LayoutService.UpdateUserPreferences" />
<ThemesButton OnClick="@(() => _themingDrawerOpen = true)" />
UserPreferencesChanged="LayoutService.UpdateUserPreferences"/>
<ThemesButton OnClick="@(() => _themingDrawerOpen = true)"/>
<MudMainContent>
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="mb-4 mt-4">
<ErrorBoundary @ref="_errorBoundary">
<ErrorBoundary @ref="ErrorBoundary">
<ChildContent>
<CascadingValue Value="@_userProfile">
@Body
Expand All @@ -42,7 +36,7 @@
</ErrorBoundary>
</MudContainer>
</MudMainContent>
<UserLoginState />
<UserLoginState/>
</Authorized>
</AuthorizeView>
</MudLayout>
Expand All @@ -54,14 +48,15 @@
private bool _navigationMenuDrawerOpen = true;
private bool _themingDrawerOpen;
private UserProfile? _userProfile;
private ErrorBoundary? _errorBoundary { set; get; }
[CascadingParameter]
private Task<AuthenticationState> AuthState { get; set; } = default!;
private ErrorBoundary? ErrorBoundary { set; get; }
[CascadingParameter] private Task<AuthenticationState> AuthState { get; set; } = default!;

protected override async Task OnInitializedAsync()
{
var state = await AuthState;
_userProfile = state.User.GetUserProfileFromClaim();
}

protected override void OnParametersSet()
{
ResetBoundary();
Expand All @@ -70,7 +65,7 @@
private void ResetBoundary()
{
// On each page navigation, reset any error state
_errorBoundary?.Recover();
ErrorBoundary?.Recover();
}

protected void NavigationMenuDrawerOpenChangedHandler(bool state)
Expand All @@ -93,13 +88,13 @@
if (!_commandPaletteOpen)
{
var options = new DialogOptions
{
NoHeader = true,
MaxWidth = MaxWidth.Medium,
FullWidth = true
};
{
NoHeader = true,
MaxWidth = MaxWidth.Medium,
FullWidth = true
};

var commandPalette = DialogService.Show<SearchDialog>("", options);
var commandPalette = await DialogService.ShowAsync<SearchDialog>("", options);
_commandPaletteOpen = true;

await commandPalette.Result;
Expand Down

0 comments on commit cb91434

Please sign in to comment.