From 5471d723a030705c349c1633faf134b137bc9a5a Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Wed, 30 Oct 2019 00:32:50 +0100 Subject: Added comment curation tool available at /comments.html --- src/comments.html | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ src/static/comments.js | 76 +++++++++++++++++++------------------ 2 files changed, 139 insertions(+), 37 deletions(-) create mode 100644 src/comments.html (limited to 'src') diff --git a/src/comments.html b/src/comments.html new file mode 100644 index 0000000..3d990da --- /dev/null +++ b/src/comments.html @@ -0,0 +1,100 @@ + + + + + + + + + Commenta dashboard + + + + + + + +

Comments

+
+ + + + + + + + + + diff --git a/src/static/comments.js b/src/static/comments.js index c8234d2..3f373e5 100644 --- a/src/static/comments.js +++ b/src/static/comments.js @@ -10,7 +10,7 @@ var firebaseConfig = { firebase.initializeApp(firebaseConfig); var database = firebase.database(); -var docPath = 'comments' + window.location.pathname.replace('.html', ''); +var docPath = window.location.hostname.replace('.', '-') + '/comments' + window.location.pathname.replace('.html', ''); var submit = document.querySelector('#submit'); var comments = document.querySelector('.comments ul'); var textName = document.querySelector('#name'); @@ -21,43 +21,45 @@ function encodeHTML(s) { return s.replace(/&/g, '&').replace(/ -
${encodeHTML(item.name)} - ${encodeHTML(item.published)}
-
${encodeHTML(item.comment)}
- `; - comments.innerHTML += liItem; - }); + // rendering html + commentList.reverse().forEach(function (item) { + var liItem = `
  • +
    ${encodeHTML(item.name)} - ${encodeHTML(item.published)}
    +
    ${encodeHTML(item.comment)}
    +
  • `; + comments.innerHTML += liItem; + }); -}, function (errorObject) { - console.log("The read failed: " + errorObject.code); -}); + }, function (errorObject) { + console.log("The read failed: " + errorObject.code); + }); -submit.addEventListener('click', function (evt) { - if (textName.value && textComment.value) { - submit.disabled = true; - firebase.database().ref(docPath + '/' + Date.now()).set({ - name: textName.value, - comment: textComment.value, - published: new Date().toISOString().slice(0, 16).replace('T', ' '), - }, function (error) { - if (error) { - alert('Data could not be saved.' + error); - } else { - textName.value = ''; - textComment.value = ''; - submit.disabled = false; - } - }); - } -}); + submit.addEventListener('click', function (evt) { + if (textName.value && textComment.value) { + submit.disabled = true; + firebase.database().ref(docPath + '/' + Date.now()).set({ + name: textName.value, + comment: textComment.value, + published: new Date().toISOString().slice(0, 16).replace('T', ' '), + }, function (error) { + if (error) { + alert('Data could not be saved.' + error); + } else { + textName.value = ''; + textComment.value = ''; + submit.disabled = false; + } + }); + } + }); +} -- cgit v1.2.3