@@ -7,6 +7,9 @@ const clearAllTaskBtn = document.querySelector("#clearAllTaskBtn");
7
7
const taskCompletedIcon = "fa-solid fa-circle-check pendingSvg" ;
8
8
const taskUncompletedIcon = "fa-regular fa-circle pendingSvg" ;
9
9
let taskCount = 3 ;
10
+ const noTasksMessage = `<div class="completed">
11
+ <p>Add a task to plan your day.</p>
12
+ </div>` ;
10
13
11
14
const completedTask = ( task ) => {
12
15
@@ -127,11 +130,40 @@ taskContainer.addEventListener("click", (e) => {
127
130
}
128
131
} ) ;
129
132
133
+ // update the count of pending tasks
130
134
const updateTaskCount = ( ) => {
135
+
136
+ // reset the taskCount
137
+ if ( taskCount < 0 )
138
+ taskCount = 0 ;
139
+
140
+ // check whether all tasks completed
131
141
if ( taskCount === 0 )
132
142
taskCountText . textContent = `Mission Accomplished!` ;
133
143
else
134
144
taskCountText . textContent = `You have ${ taskCount } pending tasks` ;
145
+
146
+ // check for no tasks in list
147
+ if ( taskCount < 2 )
148
+ updateNoTaskMessage ( ) ;
149
+ }
150
+
151
+ // add the message when no tasks are listed
152
+ const updateNoTaskMessage = ( ) => {
153
+
154
+ // if there's nothing in task-container, show the message
155
+ if ( taskContainer . childElementCount === 0 )
156
+ taskContainer . setHTML ( noTasksMessage ) ;
157
+ else if ( taskCount === 1 )
158
+ {
159
+ try {
160
+ const removeMessage = taskContainer . querySelector ( ".completed" ) ;
161
+ removeMessage . remove ( ) ;
162
+ }
163
+ catch ( error ) {
164
+ // do nothing :)
165
+ }
166
+ }
135
167
}
136
168
137
169
// remove all childs of "taskContainer" class
@@ -145,5 +177,8 @@ clearAllTaskBtn.addEventListener("click", () => {
145
177
// update task counts
146
178
taskCount = 0 ;
147
179
updateTaskCount ( ) ;
180
+
181
+ // focus the input box for typing
182
+ taskInput . focus ( ) ;
148
183
}
149
184
} ) ;
0 commit comments