From 92a4899e7c459b4537c7d9c25f99b69a921a3123 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 22 Nov 2025 02:33:22 +0800 Subject: [PATCH] :sparkles: The posts page basis --- DysonNetwork.Zone/Pages/Posts.cshtml | 62 +++++++++++++++++++ DysonNetwork.Zone/Pages/Posts.cshtml.cs | 48 ++++++++++++++ .../Pages/Shared/_LayoutContained.cshtml | 2 +- 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 DysonNetwork.Zone/Pages/Posts.cshtml create mode 100644 DysonNetwork.Zone/Pages/Posts.cshtml.cs diff --git a/DysonNetwork.Zone/Pages/Posts.cshtml b/DysonNetwork.Zone/Pages/Posts.cshtml new file mode 100644 index 0000000..3b07b88 --- /dev/null +++ b/DysonNetwork.Zone/Pages/Posts.cshtml @@ -0,0 +1,62 @@ + +@page +@model DysonNetwork.Zone.Pages.PostsModel +@using DysonNetwork.Shared.Models +@{ + Layout = "_LayoutContained"; +} + +
+

Posts

+ +
+
+ @if (Model.Posts.Any()) + { +
+ @foreach (var post in Model.Posts) + { +
+
+

@post.Title

+

@post.Content

+
+
+ Posted on @post.CreatedAt.ToDateTimeOffset().ToString("yyyy-MM-dd") +
+
+
+
+ } +
+ } + else + { +
+

No posts found.

+
+ } + + @if (Model.TotalPages > 1) + { +
+
+ @for (var i = 1; i <= Model.TotalPages; i++) + { + @i + } +
+
+ } +
+ +
+
+
+

Publisher Info

+

This is where publisher information will be displayed.

+
+
+
+
+
diff --git a/DysonNetwork.Zone/Pages/Posts.cshtml.cs b/DysonNetwork.Zone/Pages/Posts.cshtml.cs new file mode 100644 index 0000000..d67a914 --- /dev/null +++ b/DysonNetwork.Zone/Pages/Posts.cshtml.cs @@ -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 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; + } + } + } +} diff --git a/DysonNetwork.Zone/Pages/Shared/_LayoutContained.cshtml b/DysonNetwork.Zone/Pages/Shared/_LayoutContained.cshtml index 74c9fb3..125ff74 100644 --- a/DysonNetwork.Zone/Pages/Shared/_LayoutContained.cshtml +++ b/DysonNetwork.Zone/Pages/Shared/_LayoutContained.cshtml @@ -12,7 +12,7 @@