Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comment display order settings #738

Merged
merged 4 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Moonglade.Configuration/ContentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public class ContentSettings : IBlogSettings
{
[Display(Name = "Comment provider")]
public CommentProvider CommentProvider { get; set; }

[Display(Name = "Comments display order")]
public CommentOrder CommentOrder { get; set; }

[Display(Name = "Post title alignment")]
public PostTitleAlignment PostTitleAlignment { get; set; } = PostTitleAlignment.Left;
Expand Down Expand Up @@ -91,6 +94,12 @@ public enum CommentProvider
ThirdParty = 1
}

public enum CommentOrder
{
OldToNew = 0,
NewToOld = 1
}

public enum PostTitleAlignment
{
Left = 0,
Expand Down
12 changes: 9 additions & 3 deletions src/Moonglade.Web/Pages/Components/CommentList/Default.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@

@if (null != Model && Model.Any())
{
var orderedList =
BlogConfig.ContentSettings.CommentOrder == CommentOrder.NewToOld ?
Model.OrderByDescending(m => m.CreateTimeUtc) :
Model.OrderBy(m => m.CreateTimeUtc);

<div class="comment-list row">
@foreach (var item in Model.OrderBy(m => m.CreateTimeUtc))
@foreach (var item in orderedList)
{
<div class="col-md-1 mb-3 d-none d-sm-block">
@if (BlogConfig.ContentSettings.EnableGravatar && !string.IsNullOrWhiteSpace(item.Email))
Expand Down Expand Up @@ -56,9 +61,10 @@
<strong>
@SharedLocalizer["Author"]
</strong>
<span class="float-end text-muted">@SharedLocalizer["Replied at"]
<span class="float-end text-muted">
@SharedLocalizer["Replied at"]
<time data-utc-label="@reply.ReplyTimeUtc.ToString("u")">@reply.ReplyTimeUtc</time>
</span>
</span>
</div>
<p>
@Html.Raw(ContentProcessor.MarkdownToContent(reply.ReplyContent, ContentProcessor.MarkdownConvertType.Html))
Expand Down
39 changes: 29 additions & 10 deletions src/Moonglade.Web/Pages/Settings/Content.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,43 @@
<div class="col-md-5 text-end">
<div class="form-check form-check-inline">
@Html.RadioButtonFor(model => settings.CommentProvider, CommentProvider.BuiltIn, new
{
id = CommentProvider.BuiltIn.ToString(),
@class = "form-check-input comment-provider-checkbox",
onchange = "window.toggleCommentSettingsUI()"
})
{
id = CommentProvider.BuiltIn.ToString(),
@class = "form-check-input comment-provider-checkbox",
onchange = "window.toggleCommentSettingsUI()"
})
<label class="form-check-label" for="@CommentProvider.BuiltIn">@SharedLocalizer["Built in"]</label>
</div>
<div class="form-check form-check-inline">
@Html.RadioButtonFor(model => settings.CommentProvider, CommentProvider.ThirdParty, new
{
id = CommentProvider.ThirdParty.ToString(),
@class = "form-check-input comment-provider-checkbox",
onchange = "window.toggleCommentSettingsUI()"
})
{
id = CommentProvider.ThirdParty.ToString(),
@class = "form-check-input comment-provider-checkbox",
onchange = "window.toggleCommentSettingsUI()"
})
<label class="form-check-label" for="@CommentProvider.ThirdParty">@SharedLocalizer["Third party"]</label>
</div>
</div>
</div>

<div class="row g-3 align-items-center settings-entry mb-4">
<div class="col-auto">
<i class="bi-sort-numeric-down settings-entry-icon"></i>
</div>
<div class="col">
<label asp-for="@settings.CommentOrder" class="me-4"></label>
</div>
<div class="col-md-5 text-end">
<div class="form-check form-check-inline">
@Html.RadioButtonFor(model => settings.CommentOrder, CommentOrder.OldToNew, new { id = CommentOrder.OldToNew.ToString(), @class = "form-check-input" })
<label class="form-check-label" for="@CommentOrder.OldToNew">@SharedLocalizer["Old to new"]</label>
</div>
<div class="form-check form-check-inline">
@Html.RadioButtonFor(model => settings.CommentOrder, CommentOrder.NewToOld, new { id = CommentOrder.NewToOld.ToString(), @class = "form-check-input" })
<label class="form-check-label" for="@CommentOrder.NewToOld">@SharedLocalizer["New to old"]</label>
</div>
</div>
</div>

<div class="comment-settings-built-in">

Expand Down
Loading