Made sidebar item collection extendable via interface. Refactored settings to system
This commit is contained in:
49
Moonlight.Frontend/Implementations/SidebarProvider.cs
Normal file
49
Moonlight.Frontend/Implementations/SidebarProvider.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using LucideBlazor;
|
||||||
|
using Moonlight.Frontend.Interfaces;
|
||||||
|
using Moonlight.Frontend.Models;
|
||||||
|
|
||||||
|
namespace Moonlight.Frontend.Implementations;
|
||||||
|
|
||||||
|
public sealed class SidebarProvider : ISidebarProvider
|
||||||
|
{
|
||||||
|
public Task<SidebarItem[]> GetItemsAsync()
|
||||||
|
{
|
||||||
|
return Task.FromResult<SidebarItem[]>([
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Name = "Overview",
|
||||||
|
IconType = typeof(LayoutDashboardIcon),
|
||||||
|
Path = "/",
|
||||||
|
IsExactPath = true,
|
||||||
|
Order = 0
|
||||||
|
},
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Name = "Overview",
|
||||||
|
IconType = typeof(LayoutDashboardIcon),
|
||||||
|
Path = "/admin",
|
||||||
|
IsExactPath = true,
|
||||||
|
Group = "Admin",
|
||||||
|
Order = 0
|
||||||
|
},
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Name = "Users",
|
||||||
|
IconType = typeof(UsersRoundIcon),
|
||||||
|
Path = "/users",
|
||||||
|
IsExactPath = false,
|
||||||
|
Group = "Admin",
|
||||||
|
Order = 10
|
||||||
|
},
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Name = "System",
|
||||||
|
IconType = typeof(SettingsIcon),
|
||||||
|
Path = "/admin/system",
|
||||||
|
IsExactPath = false,
|
||||||
|
Group = "Admin",
|
||||||
|
Order = 20
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Moonlight.Frontend/Interfaces/ISidebarProvider.cs
Normal file
8
Moonlight.Frontend/Interfaces/ISidebarProvider.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Moonlight.Frontend.Models;
|
||||||
|
|
||||||
|
namespace Moonlight.Frontend.Interfaces;
|
||||||
|
|
||||||
|
public interface ISidebarProvider
|
||||||
|
{
|
||||||
|
public Task<SidebarItem[]> GetItemsAsync();
|
||||||
|
}
|
||||||
17
Moonlight.Frontend/Models/SidebarItem.cs
Normal file
17
Moonlight.Frontend/Models/SidebarItem.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
|
namespace Moonlight.Frontend.Models;
|
||||||
|
|
||||||
|
public record SidebarItem
|
||||||
|
{
|
||||||
|
public string Name { get; init; }
|
||||||
|
public string Path { get; init; }
|
||||||
|
public bool IsExactPath { get; init; }
|
||||||
|
public string? Group { get; init; }
|
||||||
|
public int Order { get; init; }
|
||||||
|
|
||||||
|
// Used to prevent the IL-Trimming from removing this type as its dynamically assigned a type and we
|
||||||
|
// need it to work properly
|
||||||
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
|
||||||
|
public Type IconType { get; init; }
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using Microsoft.AspNetCore.Components.Web;
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Moonlight.Frontend.Implementations;
|
||||||
|
using Moonlight.Frontend.Interfaces;
|
||||||
using Moonlight.Frontend.UI;
|
using Moonlight.Frontend.UI;
|
||||||
using ShadcnBlazor;
|
using ShadcnBlazor;
|
||||||
using ShadcnBlazor.Extras;
|
using ShadcnBlazor.Extras;
|
||||||
@@ -18,5 +20,7 @@ public partial class Startup
|
|||||||
|
|
||||||
builder.Services.AddShadcnBlazor();
|
builder.Services.AddShadcnBlazor();
|
||||||
builder.Services.AddShadcnBlazorExtras();
|
builder.Services.AddShadcnBlazorExtras();
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<ISidebarProvider, SidebarProvider>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
@page "/admin/settings"
|
@page "/admin/system"
|
||||||
@using LucideBlazor
|
@using LucideBlazor
|
||||||
@using ShadcnBlazor.Buttons
|
@using ShadcnBlazor.Buttons
|
||||||
@using ShadcnBlazor.Cards
|
@using ShadcnBlazor.Cards
|
||||||
@@ -12,10 +12,6 @@
|
|||||||
<PaintRollerIcon />
|
<PaintRollerIcon />
|
||||||
Customization
|
Customization
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
<TabsTrigger Value="authentication">
|
|
||||||
<ScanFaceIcon />
|
|
||||||
Authentication
|
|
||||||
</TabsTrigger>
|
|
||||||
<TabsTrigger Value="api">
|
<TabsTrigger Value="api">
|
||||||
<KeyIcon />
|
<KeyIcon />
|
||||||
API & API Keys
|
API & API Keys
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
@using System.Diagnostics.CodeAnalysis
|
@using Moonlight.Frontend.Interfaces
|
||||||
@using LucideBlazor
|
@using Moonlight.Frontend.Models
|
||||||
@using ShadcnBlazor.Sidebars
|
@using ShadcnBlazor.Sidebars
|
||||||
|
|
||||||
@inject NavigationManager Navigation
|
@inject NavigationManager Navigation
|
||||||
|
@inject IEnumerable<ISidebarProvider> Providers
|
||||||
|
|
||||||
@implements IDisposable
|
@implements IDisposable
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@
|
|||||||
|
|
||||||
<SidebarGroupContent>
|
<SidebarGroupContent>
|
||||||
<SidebarMenu>
|
<SidebarMenu>
|
||||||
@foreach (var item in group)
|
@foreach (var item in group.OrderBy(x => x.Order))
|
||||||
{
|
{
|
||||||
var isActive = item.IsExactPath
|
var isActive = item.IsExactPath
|
||||||
? item.Path == url.LocalPath
|
? item.Path == url.LocalPath
|
||||||
@@ -69,41 +70,14 @@
|
|||||||
{
|
{
|
||||||
private readonly List<SidebarItem> Items = new();
|
private readonly List<SidebarItem> Items = new();
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
Items.AddRange([
|
foreach (var provider in Providers)
|
||||||
new()
|
|
||||||
{
|
{
|
||||||
Name = "Overview",
|
Items.AddRange(
|
||||||
IconType = typeof(LayoutDashboardIcon),
|
await provider.GetItemsAsync()
|
||||||
Path = "/",
|
);
|
||||||
IsExactPath = true
|
|
||||||
},
|
|
||||||
new()
|
|
||||||
{
|
|
||||||
Name = "Overview",
|
|
||||||
IconType = typeof(LayoutDashboardIcon),
|
|
||||||
Path = "/admin",
|
|
||||||
IsExactPath = true,
|
|
||||||
Group = "Admin"
|
|
||||||
},
|
|
||||||
new()
|
|
||||||
{
|
|
||||||
Name = "Users",
|
|
||||||
IconType = typeof(UsersRoundIcon),
|
|
||||||
Path = "/users",
|
|
||||||
IsExactPath = false,
|
|
||||||
Group = "Admin"
|
|
||||||
},
|
|
||||||
new()
|
|
||||||
{
|
|
||||||
Name = "Settings",
|
|
||||||
IconType = typeof(SettingsIcon),
|
|
||||||
Path = "/admin/settings",
|
|
||||||
IsExactPath = false,
|
|
||||||
Group = "Admin"
|
|
||||||
}
|
}
|
||||||
]);
|
|
||||||
|
|
||||||
Navigation.LocationChanged += OnLocationChanged;
|
Navigation.LocationChanged += OnLocationChanged;
|
||||||
}
|
}
|
||||||
@@ -120,19 +94,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private record SidebarItem
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
public string Path { get; set; }
|
|
||||||
public bool IsExactPath { get; set; }
|
|
||||||
public string? Group { get; set; }
|
|
||||||
|
|
||||||
// Used to prevent the IL-Trimming from removing this type as its dynamically assigned a type and we
|
|
||||||
// need it to work properly
|
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
|
|
||||||
public Type IconType { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Navigation.LocationChanged -= OnLocationChanged;
|
Navigation.LocationChanged -= OnLocationChanged;
|
||||||
|
|||||||
Reference in New Issue
Block a user