-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #775 from EdiWang/remove-sortby
Remove "sort by" selection
- Loading branch information
Showing
5 changed files
with
11 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,22 @@ | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Moonglade.Core.PostFeature; | ||
using Moonglade.Data.Spec; | ||
using Moonglade.Web.PagedList; | ||
|
||
namespace Moonglade.Web.Pages; | ||
|
||
public class IndexModel(IBlogConfig blogConfig, ICacheAside cache, IMediator mediator) : PageModel | ||
{ | ||
public string SortBy { get; set; } | ||
|
||
public BasePagedList<PostDigest> Posts { get; set; } | ||
|
||
public async Task OnGet(int p = 1, string sortBy = "Recent") | ||
public async Task OnGet(int p = 1) | ||
{ | ||
var pagesize = blogConfig.ContentSettings.PostListPageSize; | ||
if (Enum.TryParse(sortBy, out PostsSortBy sortByEnum)) | ||
{ | ||
ViewData["sortBy"] = sortBy; | ||
|
||
var posts = await mediator.Send(new ListPostsQuery(pagesize, p, sortBy: sortByEnum)); | ||
var totalPostsCount = await cache.GetOrCreateAsync(BlogCachePartition.General.ToString(), "postcount", _ => mediator.Send(new CountPostQuery(CountType.Public))); | ||
var posts = await mediator.Send(new ListPostsQuery(pagesize, p)); | ||
var totalPostsCount = await cache.GetOrCreateAsync(BlogCachePartition.General.ToString(), "postcount", _ => mediator.Send(new CountPostQuery(CountType.Public))); | ||
|
||
var list = new BasePagedList<PostDigest>(posts, p, pagesize, totalPostsCount); | ||
var list = new BasePagedList<PostDigest>(posts, p, pagesize, totalPostsCount); | ||
|
||
Posts = list; | ||
} | ||
else | ||
{ | ||
throw new ArgumentException(message: $"Invalid argument value '{sortBy}' for argument: '{nameof(sortBy)}'!"); | ||
} | ||
Posts = list; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters