Files
blog.stevanfreeborn.com/src/Blog/Components/Posts/Feed.razor
T

42 lines
883 B
Plaintext
Raw Normal View History

2024-04-10 01:28:38 -05:00
@namespace Blog.Components
@inject IPostService postService
@inject IJSRuntime JS
2024-04-11 00:58:22 -05:00
@if (Posts is null)
{
return;
}
else if (Posts.Count == 0)
2024-04-10 01:28:38 -05:00
{
<div class="container">
<p>Looks like writers block. Check back later.</p>
</div>
}
else
{
<section role="feed" class="container">
2024-04-11 00:58:22 -05:00
@foreach (var post in Posts)
2024-04-10 01:28:38 -05:00
{
2024-04-13 19:25:38 -05:00
<article>
<NavLink href="@GetLink(post)">
2024-04-10 01:28:38 -05:00
<h3 title="@post.Title" >@post.Title</h3>
<p class="date">@post.PublishedAt.ToString("MMMM d, yyyy")</p>
<p class="lead" title="@post.Lead">@post.Lead</p>
2024-04-13 19:25:38 -05:00
</NavLink>
</article>
2024-04-10 01:28:38 -05:00
}
</section>
}
2024-04-13 19:09:03 -05:00
@code
{
2024-04-11 00:58:22 -05:00
private List<Post>? Posts;
2024-04-13 19:09:03 -05:00
private string GetLink(Post post) => $"/{post.Slug}";
2024-04-10 01:28:38 -05:00
protected override async Task OnInitializedAsync()
{
2024-04-11 00:58:22 -05:00
Posts = await postService.GetPostsAsync();
2024-04-10 01:28:38 -05:00
}
}