Files
Moonlight/Moonlight.Client/UI/Layouts/MainLayout.razor

88 lines
1.8 KiB
Plaintext

@using MoonCore.Exceptions
@using Moonlight.Client.Interfaces
@using Moonlight.Client.Services
@using Moonlight.Client.UI.Partials
@using Moonlight.Shared.Misc
@using Moonlight.Client.UI.Components
@inherits LayoutComponentBase
@inject IServiceProvider ServiceProvider
@inject ILogger<MainLayout> Logger
@inject FrontendConfiguration Configuration
<PageTitle>@Configuration.Title</PageTitle>
<ThemeLoader />
@if (IsLoading)
{
<div class="h-full w-full min-h-[100dvh] flex items-center justify-center">
<div id="loader"></div>
</div>
}
else if (CurrentScreen != null)
{
<CascadingValue Value="this" IsFixed="true">
@CurrentScreen
</CascadingValue>
}
else
{
<div>
<AppSidebar Layout="this"/>
<div class="lg:pl-72">
<AppHeader Layout="this"/>
<main class="py-10">
<div class="px-4 sm:px-6 lg:px-8">
<CascadingValue Value="this" IsFixed="true">
@Body
</CascadingValue>
</div>
</main>
</div>
</div>
}
<ToastLauncher/>
<ModalLauncher/>
@code
{
// Mobile navigation
public event Func<Task> OnStateChanged;
public bool ShowMobileNavigation { get; private set; } = false;
public async Task ToggleMobileNavigation()
{
ShowMobileNavigation = !ShowMobileNavigation;
await OnStateChanged();
}
// App loaders & screens
private bool IsLoading = true;
private RenderFragment? CurrentScreen;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
return;
await Load();
}
public async Task Load()
{
IsLoading = true;
await InvokeAsync(StateHasChanged);
//
IsLoading = false;
await InvokeAsync(StateHasChanged);
}
}