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

refactor(comment): add comment and del comment #384

Merged
merged 1 commit into from
May 18, 2023
Merged
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
56 changes: 50 additions & 6 deletions src/components/comment/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,59 @@ export default function main(_) {
$(feedbackItem[feedbackItem.length - 1]).css('padding-bottom', '0');
}
}
$(document).ajaxSuccess(function (event, xhr, settings) {
if (settings.url.includes("GetComments.aspx")) {
_.__tools.clearIntervalTimeId(_.__timeIds.commentTId);
}
});


let addComment = () => {
let userBlogAddress = $(".comment_my_posted a").attr('href'),
userName = $(".comment_my_posted a").text(),
commentInfo = $(".bq_post_comment").text();


let comment = `<div class="feedbackItem" style="padding-bottom: 0px;">
<div class="feedbackAvatar">
<a href="${userBlogAddress}" target="_blank">
<img src="${defaultAvatarImg}">
</a>
</div>
<div class="feedbackListSubtitle ${ window.isBlogOwner && 'feedbackListSubtitle-louzhu'}">
${ window.isBlogOwner && `[<span class="louzhu">楼主</span>]`}
<span class="comment_date">${(new Date).toLocaleString().replace(/\//g,'-')}</span>
<a id="a_comment_author_5168811" href="${userBlogAddress}" target="_blank">${userName}</a>
</div>
<div class="feedbackCon">
<div id="comment_body_5168811" data-format-type="Markdown" class="blog_comment_body cnblogs-markdown">
<p>${commentInfo}</p>
</div>
</div>
</div>`

$("#blog-comments-placeholder").append(comment)
$(".comment_my_posted").remove()
}

_.__timeIds.commentTId = window.setInterval(() =>{
if ($('.feedbackItem').length > 0) {
setComment();
_.__tools.clearIntervalTimeId(_.__timeIds.commentTId);
}
},1000);
}, 1000);

$(document).ajaxSuccess(function (event, xhr, settings) {
// 评论重新排序
if (settings.url.includes('GetComments.aspx')) {
_.__tools.clearIntervalTimeId(_.__timeIds.commentTId);
setComment()
}

// 新增评论
if (settings.url.includes('PostComment/Add.aspx')) addComment()

// 删除评论
if (settings.url.includes('comment/DeleteComment.aspx')) {
let commentId = JSON.parse(settings?.data)?.commentId;
$(`#comment_body_${commentId}`).parent().parent().remove()
$(".feedbackItem:last").css("padding-bottom", "0")
}
});

}