Skip to content

Commit

Permalink
Merge pull request #602 from poppastring/comment-mgmt-bug-fix
Browse files Browse the repository at this point in the history
Updating comment status will no longer switch pages. It will make it easier to manage multiple comments.
  • Loading branch information
poppastring authored Nov 23, 2021
2 parents 648949e + 38ec723 commit 5c96773
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class CommentApprovalLinkTagHelper : TagHelper

private readonly IDasBlogSettings dasBlogSettings;

private const string COMMENTAPPROVE_URL = "{0}/comments/{1}";
private const string COMMENTTEXT_MSG = "Are you sure you want to approve the comment from '{0}'?";

public CommentApprovalLinkTagHelper(IDasBlogSettings dasBlogSettings)
Expand All @@ -25,16 +24,10 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
{
var commenttxt = string.Format(COMMENTTEXT_MSG, Comment.Name);
var message = "Comment Approved";
var admin = string.Empty;

if (Admin)
{
admin = "ADMIN";
}

output.TagName = "a";
output.TagMode = TagMode.StartTagAndEndTag;
output.Attributes.SetAttribute("href", $"javascript:commentManagement(\"{Comment.BlogPostId}\",\"{Comment.CommentId}\",\"{commenttxt}\",\"PATCH\",\"{admin}\")");
output.Attributes.SetAttribute("href", $"javascript:commentManagement(\"{Comment.BlogPostId}\",\"{Comment.CommentId}\",\"{commenttxt}\",\"PATCH\")");
output.Attributes.SetAttribute("class", "dbc-comment-approve-link");

var content = await output.GetChildContentAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class CommentDeleteLinkTagHelper : TagHelper
public bool Admin { get; set; } = false;

private readonly IDasBlogSettings dasBlogSettings;
private const string COMMENTDELETE_URL = "{0}/comments/{1}";
private const string COMMENTTEXT_MSG = "Are you sure you want to delete the comment from '{0}'?";

public CommentDeleteLinkTagHelper(IDasBlogSettings dasBlogSettings)
Expand All @@ -26,17 +25,11 @@ public CommentDeleteLinkTagHelper(IDasBlogSettings dasBlogSettings)
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var commenttxt = string.Format(COMMENTTEXT_MSG, Comment.Name);
var admin = string.Empty;
var message = "Delete Comment";

if (Admin)
{
admin = "ADMIN";
}

output.TagName = "a";
output.TagMode = TagMode.StartTagAndEndTag;
output.Attributes.SetAttribute("href", $"javascript:commentManagement(\"{Comment.BlogPostId}\",\"{Comment.CommentId}\",\"{commenttxt}\",\"DELETE\",\"{admin}\")");
output.Attributes.SetAttribute("href", $"javascript:commentManagement(\"{Comment.BlogPostId}\",\"{Comment.CommentId}\",\"{commenttxt}\",\"DELETE\")");
output.Attributes.SetAttribute("class", "dbc-comment-delete-link");

var content = await output.GetChildContentAsync();
Expand Down
9 changes: 2 additions & 7 deletions source/DasBlog.Web.UI/wwwroot/js/site.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@

function commentManagement(postid, commentid, commentText, httpVerb, adminhref) {
function commentManagement(postid, commentid, commentText, httpVerb) {
if (confirm(commentText)) {
var oReq = new XMLHttpRequest();

url = 'post/' + postid + '/comments/' + commentid;

oReq.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {

if (adminhref.length != 0) {
url = 'admin/manage-comments/' + postid;
}
location.href = url;

location.href = window.location.href;
}
};

Expand Down

0 comments on commit 5c96773

Please sign in to comment.