diff --git a/ET/Web/Layout/NavMenu.razor b/ET/Web/Layout/NavMenu.razor index fa3b2a8..a2979ef 100644 --- a/ET/Web/Layout/NavMenu.razor +++ b/ET/Web/Layout/NavMenu.razor @@ -27,21 +27,23 @@ - - - @if (notes == null) + @if (groupedNotes == null) { } else { - @foreach (var note in notes) + @foreach (var group in groupedNotes) { - + + @foreach (var note in group.Notes) + { + + } } } @@ -49,7 +51,7 @@ @code { private bool collapseNavMenu = true; - private List? notes; + private List? groupedNotes; private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null; @@ -61,6 +63,16 @@ protected override async Task OnInitializedAsync() { var index = await DocsService.GetIndexAsync(); - notes = index.Notes.OrderBy(n => n.Title).ToList(); + groupedNotes = (index.Notes ?? new()) + .GroupBy(n => string.IsNullOrEmpty(n.Category) ? "Uncategorized" : n.Category) + .OrderBy(g => g.Key) + .Select(g => new NoteGroup { Category = g.Key, Notes = g.OrderBy(n => n.Title).ToList() }) + .ToList(); + } + + private class NoteGroup + { + public string Category { get; set; } = ""; + public List Notes { get; set; } = new(); } }