@page "/admin/blogposts"
@inject IBlogApi _api
<a href="/admin/blogposts/new">New blog post</a>
<ul>
    <Virtualize ItemsProvider="LoadPosts" Context="p">
        <li>
            @p.PublishDate
            <a href="/admin/blogposts/@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);
        List<BlogPost> posts = (await _api.GetBlogPostsAsync(numblogposts,request.StartIndex))??new();
        return new ItemsProviderResult<BlogPost>(posts, TotalBlogposts);
    }
}
