mirror of
https://github.com/hyzendust/hyzendust.github.io.git
synced 2026-06-30 23:12:16 +02:00
Fix: comments restructure
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -23,6 +23,7 @@
|
|||||||
var BACKEND = 'https://backend.freedoms4.org/comments.php';
|
var BACKEND = 'https://backend.freedoms4.org/comments.php';
|
||||||
var POST_ID = {{ .RelPermalink | jsonify }};
|
var POST_ID = {{ .RelPermalink | jsonify }};
|
||||||
var username = localStorage.getItem('f4_username');
|
var username = localStorage.getItem('f4_username');
|
||||||
|
var isAdmin = false;
|
||||||
|
|
||||||
var statusEl = document.getElementById('comments-status');
|
var statusEl = document.getElementById('comments-status');
|
||||||
var listEl = document.getElementById('comments-list');
|
var listEl = document.getElementById('comments-list');
|
||||||
@@ -81,15 +82,22 @@
|
|||||||
el.className = 'comment' + (depth > 0 ? ' comment--reply' : '');
|
el.className = 'comment' + (depth > 0 ? ' comment--reply' : '');
|
||||||
el.dataset.id = c.id;
|
el.dataset.id = c.id;
|
||||||
|
|
||||||
var bodyHtml = c.body === null
|
var isDeleted = c.body === null;
|
||||||
? '<span class="comment__deleted">[deleted]</span>'
|
var deletedLabel = c.deleted_label || 'deleted';
|
||||||
|
|
||||||
|
var bodyHtml = isDeleted
|
||||||
|
? '<span class="comment__deleted">[' + escHtml(deletedLabel) + ']</span>'
|
||||||
: '<p class="comment__body">' + escHtml(c.body) + '</p>';
|
: '<p class="comment__body">' + escHtml(c.body) + '</p>';
|
||||||
|
|
||||||
var actionsHtml = '';
|
var actionsHtml = '';
|
||||||
if (c.is_own && c.body !== null) {
|
|
||||||
|
// Delete button: own comment OR admin, only if not already deleted
|
||||||
|
if (!isDeleted && (c.is_own || isAdmin)) {
|
||||||
actionsHtml += '<button class="comment__action comment__action--delete" data-id="' + c.id + '">Delete</button>';
|
actionsHtml += '<button class="comment__action comment__action--delete" data-id="' + c.id + '">Delete</button>';
|
||||||
}
|
}
|
||||||
if (username && depth === 0) {
|
|
||||||
|
// Reply button: any logged-in user can reply to any non-deleted comment at any depth
|
||||||
|
if (username && !isDeleted) {
|
||||||
actionsHtml += '<button class="comment__action comment__action--reply" data-id="' + c.id + '">Reply</button>';
|
actionsHtml += '<button class="comment__action comment__action--reply" data-id="' + c.id + '">Reply</button>';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,8 +126,7 @@
|
|||||||
.then(function (r) { return r.json(); })
|
.then(function (r) { return r.json(); })
|
||||||
.then(function (d) {
|
.then(function (d) {
|
||||||
if (d.success) {
|
if (d.success) {
|
||||||
el.querySelector('.comment__body').outerHTML = '<span class="comment__deleted">[deleted]</span>';
|
loadComments();
|
||||||
delBtn.remove();
|
|
||||||
} else {
|
} else {
|
||||||
delBtn.disabled = false;
|
delBtn.disabled = false;
|
||||||
alert(d.message || 'Failed to delete.');
|
alert(d.message || 'Failed to delete.');
|
||||||
@@ -158,13 +165,15 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nested replies
|
// Nested replies — suppressed entirely when parent is deleted
|
||||||
var repliesEl = el.querySelector('.comment__replies');
|
var repliesEl = el.querySelector('.comment__replies');
|
||||||
var replyList = Array.isArray(c.replies) ? c.replies : Object.values(c.replies || {});
|
if (!isDeleted) {
|
||||||
if (replyList.length) {
|
var replyList = Array.isArray(c.replies) ? c.replies : Object.values(c.replies || {});
|
||||||
replyList.forEach(function (r) {
|
if (replyList.length) {
|
||||||
repliesEl.appendChild(renderComment(r, depth + 1));
|
replyList.forEach(function (r) {
|
||||||
});
|
repliesEl.appendChild(renderComment(r, depth + 1));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return el;
|
return el;
|
||||||
@@ -183,6 +192,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isAdmin = !!data.is_admin;
|
||||||
|
|
||||||
// Comment form for logged-in users
|
// Comment form for logged-in users
|
||||||
if (data.logged_in) {
|
if (data.logged_in) {
|
||||||
var form = makeForm('Write a comment…', 'Post comment', function (text, done) {
|
var form = makeForm('Write a comment…', 'Post comment', function (text, done) {
|
||||||
|
|||||||
Reference in New Issue
Block a user