diff --git a/Moonlight.Frontend/Implementations/SidebarProvider.cs b/Moonlight.Frontend/Implementations/SidebarProvider.cs new file mode 100644 index 00000000..5017808b --- /dev/null +++ b/Moonlight.Frontend/Implementations/SidebarProvider.cs @@ -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 GetItemsAsync() + { + return Task.FromResult([ + 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 + } + ]); + } +} \ No newline at end of file diff --git a/Moonlight.Frontend/Interfaces/ISidebarProvider.cs b/Moonlight.Frontend/Interfaces/ISidebarProvider.cs new file mode 100644 index 00000000..83a3c9f0 --- /dev/null +++ b/Moonlight.Frontend/Interfaces/ISidebarProvider.cs @@ -0,0 +1,8 @@ +using Moonlight.Frontend.Models; + +namespace Moonlight.Frontend.Interfaces; + +public interface ISidebarProvider +{ + public Task GetItemsAsync(); +} \ No newline at end of file diff --git a/Moonlight.Frontend/Models/SidebarItem.cs b/Moonlight.Frontend/Models/SidebarItem.cs new file mode 100644 index 00000000..613870ca --- /dev/null +++ b/Moonlight.Frontend/Models/SidebarItem.cs @@ -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; } +} \ No newline at end of file diff --git a/Moonlight.Frontend/Startup/Startup.Base.cs b/Moonlight.Frontend/Startup/Startup.Base.cs index 4b765ac4..33e249d7 100644 --- a/Moonlight.Frontend/Startup/Startup.Base.cs +++ b/Moonlight.Frontend/Startup/Startup.Base.cs @@ -1,6 +1,8 @@ using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.Extensions.DependencyInjection; +using Moonlight.Frontend.Implementations; +using Moonlight.Frontend.Interfaces; using Moonlight.Frontend.UI; using ShadcnBlazor; using ShadcnBlazor.Extras; @@ -18,5 +20,7 @@ public partial class Startup builder.Services.AddShadcnBlazor(); builder.Services.AddShadcnBlazorExtras(); + + builder.Services.AddSingleton(); } } \ No newline at end of file diff --git a/Moonlight.Frontend/UI/Admin/Views/Settings/Diagnose.razor b/Moonlight.Frontend/UI/Admin/Views/Sys/Diagnose.razor similarity index 100% rename from Moonlight.Frontend/UI/Admin/Views/Settings/Diagnose.razor rename to Moonlight.Frontend/UI/Admin/Views/Sys/Diagnose.razor diff --git a/Moonlight.Frontend/UI/Admin/Views/Settings/Index.razor b/Moonlight.Frontend/UI/Admin/Views/Sys/Index.razor similarity index 90% rename from Moonlight.Frontend/UI/Admin/Views/Settings/Index.razor rename to Moonlight.Frontend/UI/Admin/Views/Sys/Index.razor index 863a4b1b..9a4b9998 100644 --- a/Moonlight.Frontend/UI/Admin/Views/Settings/Index.razor +++ b/Moonlight.Frontend/UI/Admin/Views/Sys/Index.razor @@ -1,4 +1,4 @@ -@page "/admin/settings" +@page "/admin/system" @using LucideBlazor @using ShadcnBlazor.Buttons @using ShadcnBlazor.Cards @@ -12,10 +12,6 @@ Customization - - - Authentication - API & API Keys diff --git a/Moonlight.Frontend/UI/Shared/Partials/AppSidebar.razor b/Moonlight.Frontend/UI/Shared/Partials/AppSidebar.razor index 8ffef144..0fbc9d2a 100644 --- a/Moonlight.Frontend/UI/Shared/Partials/AppSidebar.razor +++ b/Moonlight.Frontend/UI/Shared/Partials/AppSidebar.razor @@ -1,8 +1,9 @@ -@using System.Diagnostics.CodeAnalysis -@using LucideBlazor +@using Moonlight.Frontend.Interfaces +@using Moonlight.Frontend.Models @using ShadcnBlazor.Sidebars @inject NavigationManager Navigation +@inject IEnumerable Providers @implements IDisposable @@ -37,7 +38,7 @@ - @foreach (var item in group) + @foreach (var item in group.OrderBy(x => x.Order)) { var isActive = item.IsExactPath ? item.Path == url.LocalPath @@ -69,42 +70,15 @@ { private readonly List Items = new(); - protected override void OnInitialized() + protected override async Task OnInitializedAsync() { - Items.AddRange([ - new() - { - Name = "Overview", - IconType = typeof(LayoutDashboardIcon), - 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" - } - ]); - + foreach (var provider in Providers) + { + Items.AddRange( + await provider.GetItemsAsync() + ); + } + 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() { Navigation.LocationChanged -= OnLocationChanged;