~jakob/blog

626e7b65e9a7c00ed68c78400e03e27cbd4c77c0 — Jakob L. Kreuze 11 months ago e446f67 feature/comment-reactions
Indicator when reaction attempt succeeded
1 files changed, 6 insertions(+), 1 deletions(-)

M haunt/static/js/comment-reaction.js
M haunt/static/js/comment-reaction.js => haunt/static/js/comment-reaction.js +6 -1
@@ 26,7 26,7 @@ function encodeAsFormData(obj) {
  return urlEncodedDataPairs.join('&');
}

function postReaction(reaction) {
function postReaction(reaction, callback) {
  let xhr = new XMLHttpRequest();
  xhr.open('POST', "/api/comment/react", true);



@@ 36,6 36,7 @@ function postReaction(reaction) {
  xhr.onload = function(data) {
    switch (xhr.status) {
    case 200:
      callback();
      break;
    case 429:
      alert("Failed -- you can react at most once an hour.");


@@ 113,6 114,10 @@ window.addEventListener("load", () => {
          postReaction({
            "id": reactButton.getAttribute("data-react-to-id"),
            "reaction": button.innerHTML
          }, () => {
            let reactAcknowledgement = document.createElement("span");
            reactAcknowledgement.innerHTML = "successfully reacted!"
            reactButton.replaceWith(reactAcknowledgement);
          });
          emojiPicker.remove();
        });