File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ const li = document.createElement('li')
2222
2323todoHandler . 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
4242async 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+
5569window . addEventListener ( "DOMContentLoaded" , fetching )
You can’t perform that action at this time.
0 commit comments