1- // Store everything imported from './todos.mjs' module as properties of an object named Todos
1+
2+ // Store everything imported from './todos.mjs' module as properties of an object named Todos
23import * as Todos from "./todos.mjs" ;
34
45// To store the todo tasks
@@ -9,14 +10,20 @@ window.addEventListener("load", () => {
910 document . getElementById ( "add-task-btn" ) . addEventListener ( "click" , addNewTodo ) ;
1011
1112 // Populate sample data
12- Todos . addTask ( todos , "Wash the dishes" , false ) ;
13+ Todos . addTask ( todos , "Wash the dishes" , false ) ;
1314 Todos . addTask ( todos , "Do the shopping" , true ) ;
1415
16+ document
17+ . getElementById ( "delete-completed-btn" )
18+ . addEventListener ( "click" , ( ) => {
19+ Todos . deleteCompleted ( todos ) ;
20+ render ( ) ;
21+ } ) ;
22+
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.
2128function 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