Skip to content

Commit 8d90817

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

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

‎Todo/app.js‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ const db = getFirestore(app);
1717
const todoHandler = document.getElementById('addTodoBtn');
1818
const todoInput = document.getElementById('todoInput');
1919
const todoList = document.getElementById('todoList');
20+
const li = document.createElement('li')
2021

2122

2223
todoHandler.addEventListener('click', async () => {
23-
let inputVal = todoInput.value
24+
let inputVal = todoInput.value.trim()
25+
if(!inputVal){
26+
alert("field is empty")
27+
return;
28+
}
29+
2430
try {
2531
await addDoc(collection(db, 'Todo'), {
2632
id: new Date().getTime(),
@@ -30,23 +36,20 @@ todoHandler.addEventListener('click', async () => {
3036
} catch (error) {
3137
console.log('The Error is in addDocs ::', error);
3238
}
39+
fetching()
40+
})
3341

42+
async function fetching() {
3443
try {
3544
const querySnapshot = await getDocs(collection(db, 'Todo'));
3645
querySnapshot.forEach((doc) => {
3746
const getId = doc.data().id
3847
const getTodo = doc.data().todo
39-
todoList.innerHTML += `
40-
<li class="todo-item">
41-
<input id= ${getId} class="inp" value=${getTodo} type="text" readonly>
42-
<button id= ${getId} class="btn-edit">Edit</button>
43-
<button id= ${getId} class="btn-delete">Delete</button>
44-
</li>
45-
`
4648
});
4749
} catch (error) {
4850
console.log('The error is in getDocs ::', error);
4951

5052
}
51-
})
53+
}
5254

55+
window.addEventListener("DOMContentLoaded", fetching)

0 commit comments

Comments
 (0)