1- // Store everything imported from './todos.mjs' module as properties of an object named Todos
1+ / S t o r e e v e r y t h i n g i m p o r t e d f r o m ' ./ todos. mjs ' module as properties of an object named Todos
22import * as Todos from "./todos.mjs" ;
33
44// To store the todo tasks
@@ -9,14 +9,20 @@ 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
15+ document
16+ . getElementById ( "delete-completed-btn" )
17+ . addEventListener ( "click" , ( ) => {
18+ Todos . deleteCompleted ( todos ) ;
19+ render ( ) ;
20+ } ) ;
21+
1522 render ( ) ;
1623} ) ;
1724
18-
19- // A callback that reads the task description from an input field and
25+ // A callback that reads the task description from an input field and
2026// append a new task to the todo list.
2127function addNewTodo ( ) {
2228 const taskInput = document . getElementById ( "new-task-input" ) ;
@@ -45,12 +51,11 @@ function render() {
4551 } ) ;
4652}
4753
48-
4954// Note:
5055// - First child of #todo-item-template is a <li> element.
5156// We will create each ToDo list item as a clone of this node.
5257// - This variable is declared here to be close to the only function that uses it.
53- const todoListItemTemplate =
58+ const todoListItemTemplate =
5459 document . getElementById ( "todo-item-template" ) . content . firstElementChild ;
5560
5661// Create a <li> element for the given todo task
@@ -62,15 +67,15 @@ function createListItem(todo, index) {
6267 li . classList . add ( "completed" ) ;
6368 }
6469
65- li . querySelector ( ' .complete-btn' ) . addEventListener ( "click" , ( ) => {
70+ li . querySelector ( " .complete-btn" ) . addEventListener ( "click" , ( ) => {
6671 Todos . toggleCompletedOnTask ( todos , index ) ;
6772 render ( ) ;
6873 } ) ;
69-
70- li . querySelector ( ' .delete-btn' ) . addEventListener ( "click" , ( ) => {
74+
75+ li . querySelector ( " .delete-btn" ) . addEventListener ( "click" , ( ) => {
7176 Todos . deleteTask ( todos , index ) ;
7277 render ( ) ;
7378 } ) ;
7479
7580 return li ;
76- }
81+ }
0 commit comments