Advertisement
pacho_the_python

Untitled

Apr 20th, 2023
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     const title_input = document.getElementById('task-title')
  3.     const category_input = document.getElementById('task-category')
  4.     const content_input = document.getElementById('task-content')
  5.     const publish_btn = document.getElementById('publish-btn')
  6.     const review_list_ul = document.getElementById('review-list')
  7.     const published_list_ul = document.getElementById('published-list')
  8.  
  9.     publish_btn.addEventListener("click", publish_task)
  10.  
  11.     function publish_task(e) {
  12.         e.preventDefault()
  13.  
  14.         let title = title_input.value
  15.         let category = category_input.value
  16.         let content = content_input.value
  17.  
  18.         let li_element = document.createElement('li')
  19.         li_element.classList.add('rpost')
  20.         review_list_ul.appendChild(li_element)
  21.  
  22.         let article_element = document.createElement('article')
  23.         li_element.appendChild(article_element)
  24.  
  25.         let h4_element = document.createElement('h4')
  26.         h4_element.textContent = `${title}`
  27.         article_element.appendChild(h4_element)
  28.  
  29.         let category_p_element = document.createElement('p')
  30.         category_p_element.textContent = `Category: ${category}`
  31.         article_element.appendChild(category_p_element)
  32.  
  33.         let content_p_element = document.createElement('p')
  34.         content_p_element.textContent = `Content: ${content}`
  35.         article_element.appendChild(content_p_element)
  36.  
  37.         let edit_btn = document.createElement('button')
  38.         edit_btn.textContent = 'Edit'
  39.         edit_btn.classList.add('action-btn')
  40.         edit_btn.classList.add('edit')
  41.         edit_btn.addEventListener("click", edit_task)
  42.         li_element.appendChild(edit_btn)
  43.  
  44.         let post_btn = document.createElement('button')
  45.         post_btn.textContent = 'Post'
  46.         post_btn.classList.add('action-btn')
  47.         post_btn.classList.add('post')
  48.         post_btn.addEventListener("click", post_task)
  49.         li_element.appendChild(post_btn)
  50.  
  51.         title_input.value = ''
  52.         category_input.value = ''
  53.         content_input.value = ''
  54.  
  55.     }
  56.  
  57.     function edit_task (edit_event) {
  58.         let event_li = edit_event.currentTarget.parentElement
  59.         let li_children = Array.from(event_li.children)
  60.         let current_article = li_children[0]
  61.         let article_children = Array.from(current_article.children)
  62.  
  63.         title_input.value = article_children[0].textContent
  64.         category_input.value = article_children[1].textContent.split(': ')[1]
  65.         content_input.value = article_children[2].textContent.split(': ')[1]
  66.  
  67.         event_li.remove()
  68.     }
  69.  
  70.     function post_task(post_event) {
  71.         let post_li = post_event.currentTarget.parentElement
  72.         post_li.lastChild.remove()
  73.         post_li.lastChild.remove()
  74.         published_list_ul.appendChild(post_li)
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement