Skip to content

Commit ca95b41

Browse files
committed
Implement deleteCompleted functionality and update event listener for completed tasks
1 parent fe74b0a commit ca95b41

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

‎Sprint-3/todo-list/script.mjs‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Store everything imported from './todos.mjs' module as properties of an object named Todos
1+
// Store everything imported from './todos.mjs' module as properties of an object named Todos
22
import * as Todos from "./todos.mjs";
33

44
// To store the todo tasks
@@ -9,14 +9,21 @@ window.addEventListener("load", () => {
99
document.getElementById("add-task-btn").addEventListener("click", addNewTodo);
1010

1111
// Populate sample data
12-
Todos.addTask(todos, "Wash the dishes", false);
12+
Todos.addTask(todos, "Wash the dishes", false);
1313
Todos.addTask(todos, "Do the shopping", true);
1414

1515
render();
16-
});
1716

17+
document
18+
.getElementById("delete-completed-btn")
19+
.addEventListener("click", () => {
20+
Todos.deleteCompleted(todos);
21+
22+
render();
23+
});
24+
});
1825

19-
// A callback that reads the task description from an input field and
26+
// A callback that reads the task description from an input field and
2027
// append a new task to the todo list.
2128
function addNewTodo() {
2229
const taskInput = document.getElementById("new-task-input");
@@ -45,12 +52,11 @@ function render() {
4552
});
4653
}
4754

48-
4955
// Note:
5056
// - First child of #todo-item-template is a <li> element.
5157
// We will create each ToDo list item as a clone of this node.
5258
// - This variable is declared here to be close to the only function that uses it.
53-
const todoListItemTemplate =
59+
const todoListItemTemplate =
5460
document.getElementById("todo-item-template").content.firstElementChild;
5561

5662
// Create a <li> element for the given todo task
@@ -62,15 +68,15 @@ function createListItem(todo, index) {
6268
li.classList.add("completed");
6369
}
6470

65-
li.querySelector('.complete-btn').addEventListener("click", () => {
71+
li.querySelector(".complete-btn").addEventListener("click", () => {
6672
Todos.toggleCompletedOnTask(todos, index);
6773
render();
6874
});
69-
70-
li.querySelector('.delete-btn').addEventListener("click", () => {
75+
76+
li.querySelector(".delete-btn").addEventListener("click", () => {
7177
Todos.deleteTask(todos, index);
7278
render();
7379
});
7480

7581
return li;
76-
}
82+
}

0 commit comments

Comments
 (0)