Skip to content

Commit d5c1df1

Browse files
committed
📝🤔Todo
1 parent 8d90817 commit d5c1df1

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

‎Todo/app.js‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const li = document.createElement('li')
2222

2323
todoHandler.addEventListener('click', async () => {
2424
let inputVal = todoInput.value.trim()
25-
if(!inputVal){
25+
if (!inputVal) {
2626
alert("field is empty")
2727
return;
2828
}
@@ -32,24 +32,38 @@ todoHandler.addEventListener('click', async () => {
3232
id: new Date().getTime(),
3333
todo: inputVal
3434
})
35+
append(inputVal)
3536
todoInput.value = ""
3637
} catch (error) {
3738
console.log('The Error is in addDocs ::', error);
3839
}
39-
fetching()
4040
})
4141

4242
async function fetching() {
4343
try {
4444
const querySnapshot = await getDocs(collection(db, 'Todo'));
45+
todoList.innerHTML = ""
4546
querySnapshot.forEach((doc) => {
4647
const getId = doc.data().id
4748
const getTodo = doc.data().todo
49+
append(getTodo)
4850
});
4951
} catch (error) {
5052
console.log('The error is in getDocs ::', error);
5153

5254
}
5355
}
5456

57+
function append(todo) {
58+
todoInput.value = ""
59+
li.innerHTML += `
60+
<li class="todo-item">
61+
<input class="inp" value=${todo} type="text" readonly>
62+
<button class="btn-edit">Edit</button>
63+
<button class="btn-delete">Delete</button>
64+
</li>
65+
`
66+
todoList.appendChild(li)
67+
}
68+
5569
window.addEventListener("DOMContentLoaded", fetching)

0 commit comments

Comments
 (0)