Advertisement
viligen

forumPosts2

Jun 23rd, 2022
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let [title, category, content, btnPublish] = document.querySelectorAll(
  3.         '#post-title, #post-category, #post-content, #publish-btn'
  4.     );
  5.  
  6.     let [ulReview, ulPublished, btnClear] = document.querySelectorAll(
  7.         '#review-list, #published-list, #clear-btn'
  8.     );
  9.  
  10.     btnPublish.addEventListener('click', (e) => {
  11.         e.preventDefault();
  12.         if ([title, category, content].some((e) => e.value == '')) {
  13.             return;
  14.         }
  15.         let [titleValue, catValue, contentValue] = [
  16.             title.value,
  17.             category.value,
  18.             content.value,
  19.         ];
  20.         let li = document.createElement('li');
  21.         li.className = 'rpost';
  22.         li.innerHTML = `<article>
  23.         <h4>${titleValue}</h4>
  24.         <p>Category: ${catValue}</p>
  25.         <p>Content: ${contentValue}</p>
  26.         </article>
  27.         <button class = "action-btn edit">Edit</button>
  28.        <button class = "action-btn approve">Approve</button> `;
  29.         let [btnEdit, btnApprove] = li.querySelectorAll('button');
  30.         ulReview.appendChild(li);
  31.         [title, category, content].forEach((e) => (e.value = ''));
  32.  
  33.         btnEdit.addEventListener('click', () => {
  34.             [title, category, content].forEach(
  35.                 (e, i) => (e.value = [titleValue, catValue, contentValue][i])
  36.             );
  37.             ulReview.removeChild(li);
  38.         });
  39.         btnApprove.addEventListener('click', () => {
  40.             ulPublished.appendChild(li);
  41.             li.removeChild(btnEdit);
  42.             li.removeChild(btnApprove);
  43.         });
  44.     });
  45.     btnClear.addEventListener('click', () => {
  46.         ulPublished.innerHTML = '';
  47.     });
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement