mirror of
https://github.com/PacktPublishing/Web-Development-with-Blazor-Second-Edition.git
synced 2025-12-06 05:32:03 +01:00
31 lines
767 B
Plaintext
31 lines
767 B
Plaintext
@page "/"
|
|
@using Data.Models.Interfaces
|
|
@using Data.Models
|
|
@inject IBlogApi _api
|
|
|
|
<ul>
|
|
<Virtualize ItemsProvider="LoadPosts" Context="p">
|
|
<li><a href="/Post/@p.Id">@p.Title</a></li>
|
|
</Virtualize>
|
|
</ul>
|
|
|
|
|
|
|
|
@code {
|
|
|
|
public int totalBlogposts { get; set; }
|
|
private async ValueTask<ItemsProviderResult<BlogPost>> LoadPosts(ItemsProviderRequest request)
|
|
{
|
|
if (totalBlogposts == 0)
|
|
{
|
|
totalBlogposts = await _api.GetBlogPostCountAsync();
|
|
}
|
|
var numblogposts = Math.Min(request.Count, totalBlogposts - request.StartIndex);
|
|
var blogposts = await _api.GetBlogPostsAsync(numblogposts, request.StartIndex);
|
|
return new ItemsProviderResult<BlogPost>(blogposts, totalBlogposts);
|
|
}
|
|
|
|
|
|
|
|
}
|