Advertisement
Guest User

Untitled

a guest
Dec 9th, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let fields = Array.from(document.querySelectorAll('input')).slice(0, 2)
  3.     let contentEl = document.getElementById("post-content")
  4.     let addBtnEl =  document.getElementById("publish-btn")
  5.     let clearBtnEl =  document.getElementById("clear-btn")
  6.  
  7.     let reviewSection = document.querySelector("#review-list");
  8.     let publSection = document.querySelector('#published-list');
  9.    
  10.     clearBtnEl.addEventListener('click',onClear)          
  11.     function onClear(e){                                  
  12.         e.preventDefault();                                
  13.         publSection.innerHTML = ''                      
  14.     }                                                      
  15.  
  16.     addBtnEl.addEventListener('click',onNext)
  17.     function onNext(e) {
  18.         e.preventDefault();
  19.         let[titleArr, categoryArr] = fields
  20.         if(!titleArr.value || !categoryArr.value || !contentEl.value) {
  21.             return;
  22.         }
  23.         const el = document.createElement('li');
  24.         el.setAttribute('class', 'rpost')
  25.         el.innerHTML = `
  26.            <article>
  27.              <h4>${titleArr.value}</h4>
  28.              <p>Category: ${categoryArr.value}</p>
  29.              <p>Content: ${contentEl.value}</p>
  30.            </article>
  31.            <button class="action-btn edit">Edit</button>
  32.            <button class="action-btn approve">Approve</button>
  33.         `        
  34.         reviewSection.appendChild(el)
  35.  
  36.         let editTitle = titleArr.value;
  37.         let editCategory = categoryArr.value;
  38.         let editPost = contentEl.value;
  39.  
  40.         fields.forEach(x => x.value = '')
  41.         contentEl.value = ""
  42.  
  43.         addBtnEl.disabled = true;
  44.    
  45.         el.querySelector('.action-btn.edit').addEventListener("click", onEdit);
  46.         function onEdit() {
  47.             titleArr.value = editTitle;
  48.             categoryArr.value = editCategory;
  49.             contentEl.value = editPost;
  50.  
  51.             reviewSection.innerHTML = ''  
  52.    
  53.           addBtnEl.disabled = false;
  54.         }
  55.         el.querySelector('.action-btn.approve').addEventListener('click', onContinue);
  56.         function onContinue() {
  57.             publSection.innerHTML = `<li class="approve-content">
  58.             <article>
  59.                <h4>${editTitle}</h4>
  60.               <p>Category: ${editCategory}</p>
  61.               <p>Content: ${editPost}</p>
  62.             </article>
  63.          </li>
  64.          `
  65.          reviewSection.innerHTML = ''          
  66.        }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement