Added page hooks for main layout
This commit is contained in:
33
Moonlight.Frontend/Configuration/LayoutPageOptions.cs
Normal file
33
Moonlight.Frontend/Configuration/LayoutPageOptions.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace Moonlight.Frontend.Configuration;
|
||||||
|
|
||||||
|
public class LayoutPageOptions
|
||||||
|
{
|
||||||
|
public IReadOnlyList<LayoutPageComponent> Components => InnerComponents;
|
||||||
|
|
||||||
|
private readonly List<LayoutPageComponent> InnerComponents = new();
|
||||||
|
|
||||||
|
public void Add<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(LayoutPageSlot slot, int order)
|
||||||
|
where T : ComponentBase
|
||||||
|
=> Add(typeof(T), slot, order);
|
||||||
|
|
||||||
|
public void Add(Type componentType, LayoutPageSlot slot, int order)
|
||||||
|
=> InnerComponents.Add(new LayoutPageComponent(componentType, order, slot));
|
||||||
|
|
||||||
|
public void Remove<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>()
|
||||||
|
where T : ComponentBase
|
||||||
|
=> Remove(typeof(T));
|
||||||
|
|
||||||
|
public void Remove(Type componentType)
|
||||||
|
=> InnerComponents.RemoveAll(x => x.ComponentType == componentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public record LayoutPageComponent(Type ComponentType, int Order, LayoutPageSlot Slot);
|
||||||
|
|
||||||
|
public enum LayoutPageSlot
|
||||||
|
{
|
||||||
|
Header = 0,
|
||||||
|
Footer = 1
|
||||||
|
}
|
||||||
@@ -1,18 +1,53 @@
|
|||||||
@using ShadcnBlazor.Extras.Alerts
|
@using Microsoft.Extensions.Options
|
||||||
|
@using Moonlight.Frontend.Configuration
|
||||||
|
@using ShadcnBlazor.Extras.Alerts
|
||||||
@using ShadcnBlazor.Sidebars
|
@using ShadcnBlazor.Sidebars
|
||||||
|
|
||||||
@inherits LayoutComponentBase
|
@inherits LayoutComponentBase
|
||||||
|
|
||||||
|
@inject IOptions<LayoutPageOptions> LayoutPageOptions
|
||||||
|
|
||||||
<SidebarProvider DefaultOpen="true">
|
<SidebarProvider DefaultOpen="true">
|
||||||
<AppSidebar/>
|
<AppSidebar/>
|
||||||
|
|
||||||
<SidebarInset>
|
<SidebarInset>
|
||||||
<AppHeader/>
|
<AppHeader/>
|
||||||
|
|
||||||
|
@foreach (var headerComponent in HeaderComponents)
|
||||||
|
{
|
||||||
|
<DynamicComponent Type="headerComponent" />
|
||||||
|
}
|
||||||
|
|
||||||
<div class="mx-8 my-8 max-w-full">
|
<div class="mx-8 my-8 max-w-full">
|
||||||
<AlertLauncher/>
|
<AlertLauncher/>
|
||||||
|
|
||||||
@Body
|
@Body
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@foreach (var footerComponent in FooterComponents)
|
||||||
|
{
|
||||||
|
<DynamicComponent Type="footerComponent" />
|
||||||
|
}
|
||||||
</SidebarInset>
|
</SidebarInset>
|
||||||
</SidebarProvider>
|
</SidebarProvider>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
private Type[] HeaderComponents;
|
||||||
|
private Type[] FooterComponents;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
HeaderComponents = LayoutPageOptions.Value.Components
|
||||||
|
.Where(x => x.Slot == LayoutPageSlot.Header)
|
||||||
|
.OrderBy(x => x.Order)
|
||||||
|
.Select(x => x.ComponentType)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
FooterComponents = LayoutPageOptions.Value.Components
|
||||||
|
.Where(x => x.Slot == LayoutPageSlot.Footer)
|
||||||
|
.OrderBy(x => x.Order)
|
||||||
|
.Select(x => x.ComponentType)
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user