mirror of
https://github.com/hyzendust/hyzendust.github.io.git
synced 2026-06-30 23:12:16 +02:00
Update: comment-box restructure
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -14,7 +14,6 @@
|
|||||||
<!-- ── Comments ── -->
|
<!-- ── Comments ── -->
|
||||||
<section class="comments" id="comments">
|
<section class="comments" id="comments">
|
||||||
<h2 class="comments__title">Comments</h2>
|
<h2 class="comments__title">Comments</h2>
|
||||||
<div id="comments-status" class="comments__status"></div>
|
|
||||||
<div id="comments-list" class="comments__list"></div>
|
<div id="comments-list" class="comments__list"></div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -25,7 +24,6 @@
|
|||||||
var username = localStorage.getItem('f4_username');
|
var username = localStorage.getItem('f4_username');
|
||||||
var isAdmin = false;
|
var isAdmin = false;
|
||||||
|
|
||||||
var statusEl = document.getElementById('comments-status');
|
|
||||||
var listEl = document.getElementById('comments-list');
|
var listEl = document.getElementById('comments-list');
|
||||||
|
|
||||||
// ── Helpers ──
|
// ── Helpers ──
|
||||||
@@ -193,10 +191,23 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
isAdmin = !!data.is_admin;
|
isAdmin = !!data.is_admin;
|
||||||
|
username = data.username || null;
|
||||||
|
|
||||||
// Comment form for logged-in users
|
// ── Render comments first ──
|
||||||
|
if (!data.comments.length) {
|
||||||
|
var empty = document.createElement('p');
|
||||||
|
empty.className = 'comments__empty';
|
||||||
|
empty.textContent = 'No comments yet. Be the first!';
|
||||||
|
listEl.appendChild(empty);
|
||||||
|
} else {
|
||||||
|
data.comments.forEach(function (c) {
|
||||||
|
listEl.appendChild(renderComment(c, 0));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Then: form (logged in) or login prompt (logged out) ──
|
||||||
if (data.logged_in) {
|
if (data.logged_in) {
|
||||||
var form = makeForm('Write a comment…', 'Post comment', function (text, done) {
|
var form = makeForm('Comment as ' + data.username + '…', 'Post comment', function (text, done) {
|
||||||
fetch(BACKEND, {
|
fetch(BACKEND, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@@ -217,18 +228,6 @@
|
|||||||
msg.innerHTML = '<a href="/login/">Log in</a> or <a href="/signup/">Sign up</a> to comment.';
|
msg.innerHTML = '<a href="/login/">Log in</a> or <a href="/signup/">Sign up</a> to comment.';
|
||||||
listEl.appendChild(msg);
|
listEl.appendChild(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.comments.length) {
|
|
||||||
var empty = document.createElement('p');
|
|
||||||
empty.className = 'comments__empty';
|
|
||||||
empty.textContent = 'No comments yet. Be the first!';
|
|
||||||
listEl.appendChild(empty);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
data.comments.forEach(function (c) {
|
|
||||||
listEl.appendChild(renderComment(c, 0));
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch(function () {
|
.catch(function () {
|
||||||
listEl.innerHTML = '<p class="comments__error">Failed to load comments.</p>';
|
listEl.innerHTML = '<p class="comments__error">Failed to load comments.</p>';
|
||||||
|
|||||||
Reference in New Issue
Block a user