Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive list #3

Merged
merged 3 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Webpack Exercise</title>
<title>Todo List</title>
<script src="https://kit.fontawesome.com/2b1476549e.js" crossorigin="anonymous"></script>
</head>
<body>
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import './style.css';
import populate from './modules/populateList.js';
import { getAddedTodos, form } from './modules/newtodo.js';
import clearAll from './modules/clearAll.js';

populate();
form.addEventListener('submit', getAddedTodos);
form.addEventListener('submit', getAddedTodos);
clearAll();
11 changes: 11 additions & 0 deletions src/modules/clearAll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createTodo, todo } from './displayData.js';

const clearButton = document.getElementById('clear-completed');
const clearAll = () => {
clearButton.addEventListener('click', () => {
todo.clearCompleted();
createTodo();
});
};

export default clearAll;
4 changes: 2 additions & 2 deletions src/modules/displayData.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export const createTodo = () => {

list.onclick = () => {
descrpt.contentEditable = 'true';
dragIcon.style.display = 'none';
list.style.backgroundColor = 'greenyellow';
list.appendChild(deleteIcon);
dragIcon.style.display = 'none';
descrpt.addEventListener('keydown', () => {
const newValue = descrpt.innerHTML;
const newValue = descrpt.innerHTML.trim();
todo.editTodo(newValue, a.index);
});
};
Expand Down
16 changes: 3 additions & 13 deletions src/modules/taskClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,9 @@ export default class TodoList {
this.allTodos = JSON.parse(localStorage.getItem('todos'));
}

editTodo() {
document.querySelectorAll('.text').forEach((b) => {
b.addEventListener('click', () => {
b.readOnly = false;
b.focus();
});
b.addEventListener('change', () => {
b.readOnly = true;
const task = this.allTodos.find((t) => t.index === Number(b.index));
task.name = b.value.trim();
this.saveTodo();
});
});
editTodo(newValue, index) {
this.allTodos[index - 1].description = newValue;
this.saveTodo();
}

completedTodo(status, index) {
Expand Down