The posts page basis

This commit is contained in:
2025-11-22 02:33:22 +08:00
parent bdc8db3091
commit 92a4899e7c
3 changed files with 111 additions and 1 deletions

View File

@@ -0,0 +1,62 @@
@page
@model DysonNetwork.Zone.Pages.PostsModel
@using DysonNetwork.Shared.Models
@{
Layout = "_LayoutContained";
}
<div class="container mx-auto px-8 pb-8">
<h1 class="text-3xl font-bold mb-8">Posts</h1>
<div class="flex flex-col md:flex-row gap-8">
<div class="w-full md:w-2/3">
@if (Model.Posts.Any())
{
<div class="space-y-8">
@foreach (var post in Model.Posts)
{
<div class="card bg-base-100 border">
<div class="card-body">
<h2 class="card-title">@post.Title</h2>
<p>@post.Content</p>
<div class="card-actions justify-end">
<div class="text-sm text-base-content/60">
Posted on @post.CreatedAt.ToDateTimeOffset().ToString("yyyy-MM-dd")
</div>
</div>
</div>
</div>
}
</div>
}
else
{
<div class="text-center py-16">
<p class="text-lg">No posts found.</p>
</div>
}
@if (Model.TotalPages > 1)
{
<div class="flex justify-center mt-8">
<div class="btn-group">
@for (var i = 1; i <= Model.TotalPages; i++)
{
<a href="/posts?currentPage=@i" class="btn @(i == Model.CurrentPage ? "btn-active" : "")">@i</a>
}
</div>
</div>
}
</div>
<div class="w-full md:w-1/3">
<div class="card bg-base-100 border">
<div class="card-body">
<h3 class="card-title">Publisher Info</h3>
<p>This is where publisher information will be displayed.</p>
</div>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,48 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Proto;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace DysonNetwork.Zone.Pages
{
public class PostsModel : PageModel
{
private readonly PostService.PostServiceClient _postClient;
public PostsModel(PostService.PostServiceClient postClient)
{
_postClient = postClient;
}
public List<SnPost> Posts { get; set; } = new();
public int TotalCount { get; set; }
public int CurrentPage { get; set; }
public int PageSize { get; set; } = 10;
public int TotalPages => (int)System.Math.Ceiling(TotalCount / (double)PageSize);
public async Task OnGetAsync(int currentPage = 1)
{
CurrentPage = currentPage;
var request = new ListPostsRequest
{
OrderBy = "date",
OrderDesc = true,
PageSize = PageSize,
PageToken = ((CurrentPage - 1) * PageSize).ToString()
};
var response = await _postClient.ListPostsAsync(request);
if (response?.Posts != null)
{
Posts = response.Posts.Select(SnPost.FromProtoValue).ToList();
TotalCount = response.TotalSize;
}
}
}
}

View File

@@ -12,7 +12,7 @@
</div>
<div class="flex-none">
<ul class="menu menu-horizontal px-1">
<li><a>Posts</a></li>
<li><a asp-page="/Posts">Posts</a></li>
<li><a asp-page="/About">About</a></li>
</ul>
</div>