Skip to content

Commit

Permalink
Fix clear button, used filter method
Browse files Browse the repository at this point in the history
  • Loading branch information
CesarHerr committed May 5, 2023
1 parent cb5ac03 commit 57f2c9a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions modules/crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TodoList {
this.list.splice(index, 1);
this.indexes();
localStorage.setItem('list', JSON.stringify(this.list));
window.location.reload();
this.displayList();
}

edit(index, newText) {
Expand All @@ -36,8 +36,8 @@ class TodoList {
mainList.innerHTML = this.list
.map(
(todo, index) => `
<li>
<span>
<li class="taskElement_master">
<span >
<input type="checkbox" class="checkbox" data-index="${index}">
<label for="name${index}"></label>
<input name="name${index}" class="taskElement" data-task-index="${index}" value="${todo.text}"></input>
Expand Down
12 changes: 5 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ document.addEventListener('change', (e) => {
const clearBtn = document.querySelector('.clear');

clearBtn.addEventListener('click', () => {
const taskDescription = document.querySelectorAll('.taskElement');
taskDescription.forEach((element) => {
if (element.classList.contains('line-through')) {
const index = element.dataset.taskIndex;
toDoList.remove(index);
}
});

console.log(toDoList.list.filter(element => element.complete !== true))
toDoList.list = toDoList.list.filter(element => element.complete !== true);
localStorage.setItem('list', JSON.stringify(toDoList.list));
window.location.reload();
});

toDoList.displayList();
Expand Down

0 comments on commit 57f2c9a

Please sign in to comment.