-
Notifications
You must be signed in to change notification settings - Fork 0
/
functionality.js
56 lines (47 loc) · 1.6 KB
/
functionality.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
const addTodo=()=>{
let newTask=textIn.value
let date=setDate.value
if(newTask !=''){
todosArray.push({
title:newTask,
checked:false,
date,
})
localStorage.setItem('todos',JSON.stringify(todosArray))
rederTodoItems()
textIn.value=''
setDate.value=''
}
}
const deleteTodo=(e)=>{
let index=parseInt(e.target.parentNode.getAttribute('key'))
todosArray.splice(index,1)
localStorage.setItem('todos',JSON.stringify(todosArray))
rederTodoItems()
}
const completeTodo=(e)=>{
let todosTemporary=[...todosArray] //copy
let index=parseInt(e.target.parentNode.getAttribute('key'))
// console.log(typeof e.target.parentNode.id)
// console.log(index)//2
let objElement=todosTemporary[index].checked
todosTemporary[index].checked= !objElement//perezapis znachenie
localStorage.setItem('todos',JSON.stringify(todosTemporary))
// console.log(todosTemporary)
let isDone = e.currentTarget.parentNode.classList.contains('taskItem-done')
if(isDone){
e.currentTarget.parentNode.classList.remove('taskItem-done')
e.currentTarget.parentNode.classList.add('taskItem')
}else{
e.currentTarget.parentNode.classList.add('taskItem-done')
e.currentTarget.parentNode.classList.remove('taskItem')
}
}
// const getTodos=()=>{
// fetch('https://jsonplaceholder.typicode.com/todos?_page=1')
// .then(response=>response.json())
// .then(array=>{
// localStorage.setItem('todos',JSON.stringify(array))
// })
// }
// getTodos()