101 lines
3.0 KiB
Plaintext
101 lines
3.0 KiB
Plaintext
@using Moonlight.Frontend.Interfaces
|
|
@using Moonlight.Frontend.Models
|
|
@using ShadcnBlazor.Sidebars
|
|
|
|
@inject NavigationManager Navigation
|
|
@inject IEnumerable<ISidebarProvider> Providers
|
|
|
|
@implements IDisposable
|
|
|
|
@{
|
|
var url = new Uri(Navigation.Uri);
|
|
}
|
|
|
|
<Sidebar Variant="SidebarVariant.Sidebar" Collapsible="SidebarCollapsible.Icon">
|
|
<SidebarHeader>
|
|
<SidebarMenu>
|
|
<SidebarMenuItem>
|
|
<SidebarMenuButton>
|
|
<a href="/" class="flex flex-row items-center">
|
|
<img alt="Logo" src="/_content/Moonlight.Frontend/logo.svg" class="size-6"/>
|
|
<span class="ms-2.5 text-lg font-semibold">Moonlight</span>
|
|
</a>
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
</SidebarMenu>
|
|
</SidebarHeader>
|
|
|
|
<SidebarContent>
|
|
@foreach (var group in Items.GroupBy(x => x.Group))
|
|
{
|
|
<SidebarGroup>
|
|
@if (!string.IsNullOrWhiteSpace(group.Key))
|
|
{
|
|
<SidebarGroupLabel>
|
|
@group.Key
|
|
</SidebarGroupLabel>
|
|
}
|
|
|
|
<SidebarGroupContent>
|
|
<SidebarMenu>
|
|
@foreach (var item in group.OrderBy(x => x.Order))
|
|
{
|
|
var isActive = item.IsExactPath
|
|
? item.Path == url.LocalPath
|
|
: url.LocalPath.StartsWith(item.Path, StringComparison.OrdinalIgnoreCase);
|
|
|
|
<SidebarMenuItem @key="item">
|
|
<SidebarMenuButton IsActive="@isActive">
|
|
<Slot>
|
|
<a href="@item.Path" @attributes="context">
|
|
<DynamicComponent Type="item.IconType"/>
|
|
<span>@item.Name</span>
|
|
</a>
|
|
</Slot>
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
}
|
|
</SidebarMenu>
|
|
</SidebarGroupContent>
|
|
</SidebarGroup>
|
|
}
|
|
</SidebarContent>
|
|
|
|
<SidebarFooter>
|
|
<NavUser/>
|
|
</SidebarFooter>
|
|
</Sidebar>
|
|
|
|
@code
|
|
{
|
|
private readonly List<SidebarItem> Items = new();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
foreach (var provider in Providers)
|
|
{
|
|
Items.AddRange(
|
|
await provider.GetItemsAsync()
|
|
);
|
|
}
|
|
|
|
Navigation.LocationChanged += OnLocationChanged;
|
|
}
|
|
|
|
private async void OnLocationChanged(object? sender, LocationChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// Ignored
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Navigation.LocationChanged -= OnLocationChanged;
|
|
}
|
|
} |