Skip to content

Commit cc2a2fb

Browse files
committed
Category detail page: shows, links to individual posts
1 parent d5abfa1 commit cc2a2fb

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@page "/category/{CategoryName}"
2+
3+
<h3>Category: @CategoryName</h3>
4+
5+
@if (!Items.Any())
6+
{
7+
<p>No posts found in this category.</p>
8+
}
9+
else
10+
{
11+
<ul>
12+
@foreach (var item in Items)
13+
{
14+
<li class="mb-3">
15+
<strong>
16+
<a href="/content-item/edit/@item.Id">@item.Title</a>
17+
</strong>
18+
<div>
19+
@item.Summary
20+
</div>
21+
<small>Published @item.DatePublished.ToString("yyyy-MM-dd")</small>
22+
</li>
23+
}
24+
</ul>
25+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.AspNetCore.Components;
2+
using MoonPress.Core.Content;
3+
using MoonPress.Core.Models;
4+
5+
namespace MoonPress.BlazorDesktop.Components.Pages.Categories;
6+
7+
public partial class CategoryDetail : ComponentBase
8+
{
9+
[Parameter]
10+
public string CategoryName { get; set; } = string.Empty;
11+
12+
private List<ContentItem> Items = new();
13+
14+
protected override void OnParametersSet()
15+
{
16+
var all = ContentItemFetcher.GetItemsByCategory();
17+
if (all.TryGetValue(CategoryName, out var items))
18+
{
19+
Items = items
20+
.OrderByDescending(i => i.DatePublished)
21+
.ToList();
22+
}
23+
else
24+
{
25+
Items = new List<ContentItem>();
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)