-
Notifications
You must be signed in to change notification settings - Fork 0
/
criaTarefa.js
52 lines (33 loc) · 1.29 KB
/
criaTarefa.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import BotaoConclui from './concluiTarefa.js'
import BotaoDeleta from './deletaTarefa.js'
export const handleNovoItem = (evento) => {
evento.preventDefault()
const tarefas = JSON.parse(localStorage.getItem('tarefas')) || []
const lista = document.querySelector('[data-list]')
const input = document.querySelector('[data-form-input]')
const valor = input.value
sessionStorage
const calendario = document.querySelector('[data-form-date]')
const data = moment(calendario.value)
const dataFormatada = data.format('DD/MM/YYYY')
const dados = {
valor,
dataFormatada
}
const tarefasAtualizadas = [...tarefas, dados]
const criaTarefa = Tarefa(dados)
lista.appendChild(criaTarefa)
localStorage.setItem('tarefas', JSON.stringify(tarefasAtualizadas))
input.value = " "
}
export const Tarefa = ({ valor, dataFormatada }) => {
const tarefa = document.createElement('li')
tarefa.classList.add('task')
const conteudo = `<p class="content">${dataFormatada} * ${valor}</p>`
tarefa.innerHTML = conteudo
tarefa.appendChild(BotaoConclui())
tarefa.appendChild(BotaoDeleta())
return tarefa
}
const novaTarefa = document.querySelector('[data-form-button]')
novaTarefa.addEventListener('click', handleNovoItem)