-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
35 lines (27 loc) · 1.05 KB
/
script.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
const form = document.querySelector("#form-habits")
const nlwSetup = new NLWSetup(form)//inicia biblioteca
const button = document.querySelector('header button')
button.addEventListener('click', add)
form.addEventListener('change', save)
function add() {
const today = new Date().toLocaleDateString("pt-br").slice(0, 5)
const dayExists = nlwSetup.dayExists(today) //Verifica se o dia já existe no conjunto de dias
if(dayExists){
alert("Dia já adicionado!")
return
}
nlwSetup.addDay(today) //Adiciona um dia aos dias registrados e renderiza o layout depois disso
}
function save() {
//localStorage.NLWSetupHabits = JSON.stringify(nlwSetup.data)
localStorage.setItem("NLWSetup@habits",JSON.stringify(nlwSetup.data))
}
// const data = {
// run: ["01-01", "01-02", "01-06"],
// read: ["01-02", "01-05"],
// takePills: ["01-01", "01-02", "01-05", "01-06", "01-07"],
// ride: ["01-01", "01-02", "01-05", "01-06", "01-07"],
// }
const data = JSON.parse(localStorage.getItem("NLWSetup@habits")) ||{}
nlwSetup.setData(data)
nlwSetup.load()