-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (48 loc) · 1.8 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
const todos = [];
const get = (elements) => elements.map((element) => document.getElementById(element));
const [pendingList,completedList,newTodo,addForm] = get(["pendinglist","completedlist","newTodo","addForm"]);
const newList = [
{
element: pendingList,
status: "pending",
},
{
element: completedList,
status: "done",
},
];
const cssClasses = {
pending:"bg-blue-400 w-full text-center text-white rounded py-4 border-2 border-blue-500 transition transform ease-in-out duration-300 hover:bg-blue-500 hover:text-white hover:scale-110 hover:-rotate-1 cursor-pointer",
done: "bg-yellow-400 w-full text-center text-white rounded py-4 border-2 border-yellow-500 transition transform ease-in-out duration-300 hover:bg-yellow-500 hover:text-white hover:scale-110 hover:rotate-1 cursor-pointer"
};
const updateTodos = () => {
newList.forEach(list => {
const filteredTodos = todos.filter((todo) => todo.status === list.status);
list.element.innerHTML = "";
filteredTodos.forEach((todo) => {
const item = document.createElement('li');
item.className= cssClasses[list.status];
item.innerText= todo.text;
item.id = todo.id;
list.element.appendChild(item);
});
});
};
addForm.addEventListener('submit', event=>{
event.preventDefault();
todos.push({
id: Math.floor(Math.random() * 100000).toString(),
text: newTodo.value,
status: "pending",
});
newTodo.value = "";
updateTodos();
});
pendingList.addEventListener('click',(event)=>{
todos.find(todo => todo.id === event.target.id).status = "done";
updateTodos();
});
completedList.addEventListener('click',(event)=>{
todos.find(todo => todo.id === event.target.id).status = "pending";
updateTodos();
});