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
2+
23import * as Todos from "./todos.mjs" ;
34
45// To store the todo tasks
56const todos = [ ] ;
67
78// Set up tasks to be performed once on page load
89window . addEventListener ( "load" , ( ) => {
10+ //get the deleted complete button from html
11+ const massDeleteBtn = document . querySelector ( "#delete-completed-btn" ) ;
12+
13+ // check if the button is even found in the HTML
14+ // console.log("Button found:", massDeleteBtn);
15+
16+ if ( massDeleteBtn ) {
17+ massDeleteBtn . addEventListener ( "click" , ( ) => {
18+ // check if the click event is firing
19+ // console.log("Mass delete button clicked!");
20+ // console.log("Todos before delete:", JSON.parse(JSON.stringify(todos)));
21+ Todos . deleteCompleted ( todos ) ;
22+ // check if the array actually changed
23+ // console.log("Todos after delete:", JSON.parse(JSON.stringify(todos)));
24+ render ( ) ;
25+ } ) ;
26+ }
27+
928 document . getElementById ( "add-task-btn" ) . addEventListener ( "click" , addNewTodo ) ;
1029
1130 // Populate sample data
12- Todos . addTask ( todos , "Wash the dishes" , false ) ;
31+ Todos . addTask ( todos , "Wash the dishes" , false ) ;
1332 Todos . addTask ( todos , "Do the shopping" , true ) ;
1433
1534 render ( ) ;
1635} ) ;
1736
1837
19- // A callback that reads the task description from an input field and
38+ // A callback that reads the task description from an input field and
2039// append a new task to the todo list.
2140function addNewTodo ( ) {
2241 const taskInput = document . getElementById ( "new-task-input" ) ;
@@ -31,7 +50,7 @@ function addNewTodo() {
3150
3251// Note:
3352// - Store the reference to the <ul> element with id "todo-list" here
34- // to avoid querying the DOM repeatedly inside render().
53+ // to avoid querying the DOM repeatedly inside render().
3554// - This variable is declared here to be close to the only function that uses it.
3655const todoListEl = document . getElementById ( "todo-list" ) ;
3756
@@ -48,9 +67,9 @@ function render() {
4867
4968// Note:
5069// - First child of #todo-item-template is a <li> element.
51- // We will create each ToDo list item as a clone of this node.
70+ // We will create each ToDo list item as a clone of this node.
5271// - This variable is declared here to be close to the only function that uses it.
53- const todoListItemTemplate =
72+ const todoListItemTemplate =
5473 document . getElementById ( "todo-item-template" ) . content . firstElementChild ;
5574
5675// Create a <li> element for the given todo task
@@ -62,15 +81,15 @@ function createListItem(todo, index) {
6281 li . classList . add ( "completed" ) ;
6382 }
6483
65- li . querySelector ( ' .complete-btn' ) . addEventListener ( "click" , ( ) => {
84+ li . querySelector ( " .complete-btn" ) . addEventListener ( "click" , ( ) => {
6685 Todos . toggleCompletedOnTask ( todos , index ) ;
6786 render ( ) ;
6887 } ) ;
69-
70- li . querySelector ( ' .delete-btn' ) . addEventListener ( "click" , ( ) => {
88+
89+ li . querySelector ( " .delete-btn" ) . addEventListener ( "click" , ( ) => {
7190 Todos . deleteTask ( todos , index ) ;
7291 render ( ) ;
7392 } ) ;
7493
7594 return li ;
76- }
95+ }
0 commit comments