diff --git a/files/templates/comments.html b/files/templates/comments.html index b9570a96d..9a3dbea2f 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -83,22 +83,25 @@ }; - document.getElementById('reportCommentModal').addEventListener('hidden.bs.modal', function () { + document.addEventListener("DOMContentLoaded", function() { - var button = document.getElementById("reportCommentButton"); + document.getElementById('reportCommentModal').addEventListener('hidden.bs.modal', function () { - var beforeModal = document.getElementById("reportCommentFormBefore"); - var afterModal = document.getElementById("reportCommentFormAfter"); + const button = document.getElementById("reportCommentButton"); - button.innerHTML='Report comment'; - button.disabled= false; - afterModal.classList.add('d-none'); + const beforeModal = document.getElementById("reportCommentFormBefore"); + const afterModal = document.getElementById("reportCommentFormAfter"); - if ( beforeModal.classList.contains('d-none') ) { - beforeModal.classList.remove('d-none'); - } + button.innerHTML = 'Report comment'; + button.disabled = false; + afterModal.classList.add('d-none'); - }); + if (beforeModal.classList.contains('d-none')) { + beforeModal.classList.remove('d-none'); + } + + }); + }); //Commenting form @@ -147,7 +150,7 @@ }; - post_comment=function(fullname){ + post_comment=function(fullname, postId){ var form = new FormData(); @@ -168,6 +171,8 @@ myToast.hide(); var myToast = new bootstrap.Toast(document.getElementById('toast-post-success')); myToast.show(); + + incrementCommentCount(postId) } else { var commentError = document.getElementById("comment-error-text"); @@ -758,10 +763,10 @@ Cancel - Comment + Comment Cancel - Comment + Comment diff --git a/files/templates/default.html b/files/templates/default.html index c52d3b78a..6cd578455 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -219,11 +219,15 @@ function showNewCommentCounts(postId, lastTotalComs) { const comments = JSON.parse(localStorage.getItem(COMMENT_COUNTS_ID)) || {} - const lastCount = comments["" + postId] + console.log(postId) + const lastCount = comments[postId] + console.log(lastCount) if (lastCount) { - const newComments = lastTotalComs - lastCount.p + const newComments = lastTotalComs - lastCount.c + console.log('new:', newComments) if (newComments > 0) { document.querySelectorAll(`#post-${postId} .new-comments`).forEach(elem => { + console.log(elem) elem.textContent = ` (+${newComments})` elem.classList.remove("d-none") }) @@ -231,6 +235,10 @@ } } + function incrementCommentCount(postId) { + saveCommentsCount(postId) + } + /** * Saves the comment count to the localStorage * @@ -240,14 +248,13 @@ function saveCommentsCount(postId, lastTotalComs = null) { const comments = JSON.parse(localStorage.getItem(COMMENT_COUNTS_ID)) || {} - lastTotalComs = lastTotalComs || (comments["" + postId] || { c: 0 }).c + 1 + const newTotal = lastTotalComs || ((comments[postId] || { c: 0 }).c + 1) - comments["" + postId] = { p: lastTotalComs, t: Date.now() } + console.log(newTotal) + comments[postId] = { c: newTotal, t: Date.now() } window.localStorage.setItem(COMMENT_COUNTS_ID, JSON.stringify(comments)) - //TODO: increment count on submit response and new comment - //TODO: restrict on display unread comments flag } @@ -271,10 +278,8 @@ delete comments[key] } } - window.localStorage.setItem(COMMENT_COUNTS_ID, JSON.stringify(comments)) } - window.localStorage.setItem(LAST_CACHE_CLEAN_ID, JSON.stringify(now)) } diff --git a/files/templates/report_post_modal.html b/files/templates/report_post_modal.html index 6cba89fbf..7ddd4c658 100644 --- a/files/templates/report_post_modal.html +++ b/files/templates/report_post_modal.html @@ -31,23 +31,25 @@ } }; - document.getElementById('reportPostModal').addEventListener('hidden.bs.modal', function () { + document.addEventListener("DOMContentLoaded", function() { + document.getElementById('reportPostModal').addEventListener('hidden.bs.modal', function () { - var button = document.getElementById("reportPostButton"); + const button = document.getElementById("reportPostButton"); - var beforeModal = document.getElementById("reportPostFormBefore"); - var afterModal = document.getElementById("reportPostFormAfter"); + const beforeModal = document.getElementById("reportPostFormBefore"); + const afterModal = document.getElementById("reportPostFormAfter"); - button.innerHTML='Report post'; - button.disabled= false; + button.innerHTML = 'Report post'; + button.disabled = false; - afterModal.classList.add('d-none'); + afterModal.classList.add('d-none'); - if ( beforeModal.classList.contains('d-none') ) { - beforeModal.classList.remove('d-none'); - } + if (beforeModal.classList.contains('d-none')) { + beforeModal.classList.remove('d-none'); + } - }); + }); + }) diff --git a/files/templates/submission.html b/files/templates/submission.html index 0bfe8d048..010cc6158 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -37,7 +37,7 @@ {% if v %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index c7fdcbe69..c17027d7d 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -141,8 +141,12 @@ {% if p.realbody(v) %}
  • {% endif %} -
  • {{p.comment_count}}
  • - +
  • + + {{p.comment_count}} + + +
  • Votes
  • {% if v and v.id!=p.author_id %} @@ -229,8 +233,12 @@