generated from github/codespaces-blank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
96 lines (77 loc) · 3.04 KB
/
app.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const checkboxList = document.querySelectorAll('.custom-checkbox')
const inputField = document.querySelectorAll('.goal-input')
const errorLable = document.querySelector('.error-lable')
const progessBar = document.querySelector('.progress-bar')
const goalLevel = document.querySelector('.progress-level')
const progressLable = document.querySelector('.progress-lable')
const allQuotes = [
"Raise the bar by completing your goals!",
"Well begun is half done!",
"Just a step away, keep going!",
"Whoa! You just completed all the goals, time for chill :D",
]
// const setGoal = JSON.parse(localStorage.getItem('setGoal')) || {
// firstInput : {
// name: "",
// done : false,
// },
// secoundInput: {
// name: "",
// done : false,
// },
// thiredInput: {
// name: "",
// done : false,
// }
// };
const setGoal = JSON.parse(localStorage.getItem('setGoal')) || {}
let complateGoalCount = Object.values(setGoal).filter((goal) => goal.done).length;
goalLevel.style.width = `${complateGoalCount / inputField.length *100}%`;
goalLevel.firstElementChild.innerText = `${complateGoalCount}/${inputField.length} Completed`;
progressLable.innerText = allQuotes[complateGoalCount]
checkboxList.forEach((checkBox => {
checkBox.addEventListener('click', (e)=>{
const allFieldfilled = [...inputField].every((input)=>{
return input.value
})
if (allFieldfilled){
checkBox.parentElement.classList.toggle('done')
const inputID = checkBox.nextElementSibling.id
setGoal[inputID].done = !setGoal[inputID].done
complateGoalCount = Object.values(setGoal).filter((goal) => goal.done).length;
goalLevel.style.width = `${complateGoalCount / inputField.length *100}%`;
goalLevel.firstElementChild.innerText = `${complateGoalCount}/${inputField.length} Completed`;
progressLable.innerText = allQuotes[complateGoalCount]
localStorage.setItem('setGoal', JSON.stringify(setGoal))
console.log(setGoal)
}else{
progessBar.classList.add('show-error')
}
} )
}))
inputField.forEach((input)=>{
if(setGoal[input.id]){
input.value = setGoal[input.id].name
if(setGoal[input.id].done){
input.parentElement.classList.add('done')
}
}
input.addEventListener('focus', ()=>{
progessBar.classList.remove('show-error')
})
input.addEventListener('input', (e)=>{
if(setGoal[input.id] && setGoal[input.id].done){
input.value = setGoal[input.id].name
return
}
if(setGoal[input.id]){
setGoal[input.id].name = input.value
}else{
setGoal[input.id] = {
name : input.value,
done : false,
}
}
localStorage.setItem('setGoal', JSON.stringify(setGoal))
})
})