diff --git a/assets/js/app.js b/assets/js/app.js index 5323e85..8e3b07e 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -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; } @@ -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(); diff --git a/constant.js b/constant.js new file mode 100644 index 0000000..30b1702 --- /dev/null +++ b/constant.js @@ -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!' +} \ No newline at end of file diff --git a/index.html b/index.html index ccad26f..e88c047 100644 --- a/index.html +++ b/index.html @@ -106,6 +106,7 @@

Made with by Avinash

+