Advertisement
Guest User

Untitled

a guest
Oct 24th, 2019
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function mySolution() {
  2.     const sendBtn = document.querySelector("#inputSection > div > button");
  3.     const pendingQuestions = document.getElementById('pendingQuestions');
  4.     const openQuestions = document.getElementById('openQuestions');
  5.  
  6.     sendBtn.addEventListener('click', () => {
  7.         let question = document.querySelector('#inputSection > textarea').value;
  8.         let username = document.querySelector("#inputSection > div > input[type=username]").value;
  9.         createQuestion(true, question, username);
  10.     });
  11.  
  12.     function createQuestion(isPending, question, username) {
  13.         if(isPending) {
  14.             pendingQuestions.innerHTML =
  15.                 `<h3>Pending Questions</h3>` +
  16.                 '<div class="pendingQuestion">' +
  17.                     '<img src = "./images/user.png" width="32" height="32">' +
  18.                     `<span>${username ? username : "Anonymous"}</span>` +
  19.                     `<p>${question}</p>` +
  20.                     '<div class="actions">' +
  21.                         '<button class="archive">Archive</button>' +
  22.                         '<button class="open">Open</button>' +
  23.                     '</div>' +
  24.                 '</div>';
  25.             const archiveBtn = document.querySelector("#pendingQuestions > div > div > button.archive");
  26.             archiveBtn.addEventListener('click', function() {
  27.                 removeEl(this);
  28.             });
  29.             const openBtn = document.querySelector("#pendingQuestions > div > div > button.open");
  30.             openBtn.addEventListener('click', function() {
  31.                 document.querySelector('#inputSection > textarea').value = '';
  32.                 document.querySelector("#inputSection > div > input[type=username]").value = '';
  33.                 removeEl(this);
  34.                 createQuestion(false, question, username);
  35.             });
  36.         } else {
  37.             openQuestions.innerHTML =  `<h3>Open Questions</h3>` +
  38.                 '<div class="openQuestion">' +
  39.                     '<img src = "./images/user.png" width="32" height="32">' +
  40.                     `<span>${username ? username : "Anonymous"}</span>` +
  41.                     `<p>${question}</p>` +
  42.                         '<div class="actions">' +
  43.                             '<button class="reply">Reply</button>' +
  44.                         '</div>' +
  45.                         '<div class="replySection" style="display: none;">' +
  46.                             '<input class="replyInput" type="text" placeholder="Reply to this question here..."></input>' +
  47.                             '<button class="replyButton">Send</button>' +
  48.                             '<ol class="reply" type="1"></ol>' +
  49.                         '</div>' +
  50.                 '</div>';
  51.             const replyBtn = document.querySelector("#openQuestions > div > div.actions > button");
  52.             replyBtn.addEventListener('click', function() {
  53.                 let replySection = document.querySelector("#openQuestions > div > div.replySection");
  54.                 if (replyBtn.textContent === 'Reply') {
  55.                     replySection.style.display = 'block';
  56.                     replyBtn.textContent = 'Back';
  57.                 } else {
  58.                     replySection.style.display = 'none';
  59.                     replyBtn.textContent = 'Reply';
  60.                 }
  61.  
  62.                 const sendBtn = document.querySelector("#openQuestions > div > div.replySection > button.replyButton");
  63.  
  64.                 sendBtn.addEventListener('click', () => {
  65.                     let replyText = document.querySelector("#openQuestions > div > div.replySection > input.replyInput").value;
  66.                     if (replyText) {
  67.                         const answerList = document.querySelector("#openQuestions > div > div.replySection > ol.reply");
  68.                         let li = document.createElement('li');
  69.                         li.textContent = replyText;
  70.                         answerList.appendChild(li);
  71.                         document.querySelector("#openQuestions > div > div.replySection > input.replyInput").value = '';
  72.                     }
  73.                 });
  74.             });
  75.         }
  76.     }
  77.  
  78.     function removeEl(el) {
  79.         let elementToRemove = el.parentNode.parentNode;
  80.         elementToRemove.parentNode.removeChild(elementToRemove);
  81.     }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement