Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 24 additions & 26 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ function addTodo(e) {
const currentValue = htmlEncode(todoInput.value)?.trim() || ""
if (!currentValue) {
//alert("Fill the box");
openmodal("red", "Please enter a Task!");
openmodal("red", StaticLabels.ENTER_TASK_MESSAGE);
return;
}

// alert("Duplicate task")
if (isDuplicate(currentValue)) {
openmodal('red', 'This Task is already added!');
openmodal('red', StaticLabels.ENTER_TASK_MESSAGE);
return;
}

Expand Down Expand Up @@ -146,33 +146,31 @@ function filterTodo(e) {
const todos = todoList.childNodes;
todos.forEach((todo) => {
// console.log(e.target.value);

if (
e.target.value === "completed" &&
todo.classList.contains("completed")
) {
todo.style.display = "flex";
} else if (
e.target.value === "completed" &&
!todo.classList.contains("completed")
) {
todo.style.display = "none";
} else if (
e.target.value === "incomplete" &&
!todo.classList.contains("completed")
) {
todo.style.display = "flex";
} else if (
e.target.value === "incomplete" &&
!todo.classList.contains("incomplete")
) {
todo.style.display = "none";
} else {
todo.style.display = "flex";
}
filterTodos(e, todo);

});
}

//function to return todos based upon status
function filterTodos(e, todo) {
if (e.target.value === "completed" &&
todo.classList.contains("completed")) {
todo.style.display = "flex";
} else if (e.target.value === "completed" &&
!todo.classList.contains("completed")) {
todo.style.display = "none";
} else if (e.target.value === "incomplete" &&
!todo.classList.contains("completed")) {
todo.style.display = "flex";
} else if (e.target.value === "incomplete" &&
!todo.classList.contains("incomplete")) {
todo.style.display = "none";
} else {
todo.style.display = "flex";
}
}


//save the task to the local storage
function saveLocalTodos(todo) {
let todos = getItemFromLocalStorage();
Expand Down
6 changes: 6 additions & 0 deletions constant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//add static labels to utilized in another JS file instead of hardcode strings
const StaticLabels={
SHOWALERT_VALIDATION_MESSAGE:'Please add items first',
ENTER_TASK_MESSAGE:'Please enter a Task!',
TASK_ALREADY_EIXIST_MESSAGE:'This Task is already added!'
}
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ <h3>Made with <i class="fas fa-heart"></i> by Avinash</h3>
</footer>

<script src="assets/js/app.js"></script>
<script src="./constant.js"></script>

</body>

Expand Down