Skip to content

Commit 6ee434e

Browse files
committed
Fix: no task listed function message
1 parent dae9aec commit 6ee434e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

script.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const clearAllTaskBtn = document.querySelector("#clearAllTaskBtn");
77
const taskCompletedIcon = "fa-solid fa-circle-check pendingSvg";
88
const taskUncompletedIcon = "fa-regular fa-circle pendingSvg";
99
let taskCount = 3;
10+
const noTasksMessage = `<div class="completed">
11+
<p>Add a task to plan your day.</p>
12+
</div>`;
1013

1114
const completedTask = (task) => {
1215

@@ -127,11 +130,40 @@ taskContainer.addEventListener("click", (e) => {
127130
}
128131
});
129132

133+
// update the count of pending tasks
130134
const updateTaskCount = () => {
135+
136+
// reset the taskCount
137+
if(taskCount < 0)
138+
taskCount = 0;
139+
140+
// check whether all tasks completed
131141
if(taskCount === 0)
132142
taskCountText.textContent = `Mission Accomplished!`;
133143
else
134144
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+
}
135167
}
136168

137169
// remove all childs of "taskContainer" class
@@ -145,5 +177,8 @@ clearAllTaskBtn.addEventListener("click", () => {
145177
// update task counts
146178
taskCount = 0;
147179
updateTaskCount();
180+
181+
// focus the input box for typing
182+
taskInput.focus();
148183
}
149184
});

style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,7 @@ body {
153153
.task.checked > .editSvg {
154154
display: none;
155155
}
156+
/* No Task Message */
157+
.completed {
158+
text-align: center;
159+
}

0 commit comments

Comments
 (0)