Skip to content

Commit a83d04f

Browse files
committed
Calls deleteCompleted()
1 parent 0c1b74c commit a83d04f

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
@@ -7,16 +7,23 @@ const todos = [];
77
// Set up tasks to be performed once on page load
88
window.addEventListener("load", () => {
99
document.getElementById("add-task-btn").addEventListener("click", addNewTodo);
10+
document
11+
.getElementById("delete-completed-btn")
12+
.addEventListener("click", () => {
13+
const updated = Todos.deleteCompleted(todos);
14+
todos.length = 0;
15+
todos.push(...updated);
16+
render();
17+
});
1018

1119
// Populate sample data
12-
Todos.addTask(todos, "Wash the dishes", false);
20+
Todos.addTask(todos, "Wash the dishes", false);
1321
Todos.addTask(todos, "Do the shopping", true);
1422

1523
render();
1624
});
1725

18-
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)