init
This commit is contained in:
33
OpenArchival.Blazor.Blog/LatestBlogPostsSlider.razor
Normal file
33
OpenArchival.Blazor.Blog/LatestBlogPostsSlider.razor
Normal file
@@ -0,0 +1,33 @@
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using OpenArchival.DataAccess
|
||||
@using MudBlazor
|
||||
|
||||
@namespace OpenArchival.Blazor.Blog
|
||||
|
||||
<MudPaper Class="pa-4 ma-2 rounded" Elevation="3" Style="overflow-x:auto">
|
||||
<MudText Typo="Typo.h6">Latest Blog Posts</MudText>
|
||||
<MudDivider/>
|
||||
<MudStack Row="true" Spacing="4" Style="flex-wrap: nowrap;" Class="mt-4">
|
||||
@foreach (BlogPost post in BlogPosts)
|
||||
{
|
||||
<div style="min-width: 300px;">
|
||||
<BlogPostCard Post="post" Height="300"></BlogPostCard>
|
||||
</div>
|
||||
}
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
|
||||
@inject IDbContextFactory<ApplicationDbContext> ContextFactory;
|
||||
@code {
|
||||
private List<BlogPost> BlogPosts { get; set; } = [];
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await using var context = await ContextFactory.CreateDbContextAsync();
|
||||
BlogPosts = await context.BlogPosts
|
||||
.Include(p => p.MainPhoto)
|
||||
.OrderByDescending(p => p.CreationTime)
|
||||
.Take(10)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user