@@ -18,24 +18,24 @@ const todoHandler = document.getElementById('addTodoBtn');
1818const todoInput = document . getElementById ( 'todoInput' ) ;
1919const main = document . getElementById ( 'main' ) ;
2020const ul = document . createElement ( 'ul' )
21+ // const li = document.createElement('li')
2122ul . className = "todo-list"
2223ul . id = "todoList"
2324
2425
2526todoHandler . addEventListener ( 'click' , async ( ) => {
2627 let inputVal = todoInput . value . trim ( )
27- let id = new Date ( ) . getTime ( )
2828 if ( ! inputVal ) {
2929 alert ( "field is empty" )
3030 return ;
3131 }
3232
3333 try {
3434 await addDoc ( collection ( db , 'Todo' ) , {
35- id : id ,
35+ id : new Date ( ) . getTime ( ) ,
3636 todo : inputVal
3737 } )
38- append ( id , inputVal )
38+ append ( inputVal )
3939 todoInput . value = ""
4040 } catch ( error ) {
4141 console . log ( 'The Error is in addDocs ::' , error ) ;
@@ -49,25 +49,26 @@ async function fetching() {
4949 querySnapshot . forEach ( ( doc ) => {
5050 const getId = doc . data ( ) . id
5151 const getTodo = doc . data ( ) . todo
52- append ( getId , getTodo )
53- // edit(getId, getTodo)
52+ append ( getTodo )
5453 } ) ;
5554 } catch ( error ) {
5655 console . log ( 'The error is in getDocs ::' , error ) ;
5756
5857 }
5958}
60-
61- function append ( id , todo ) {
59+ const array = [ ]
60+ function append ( todo ) {
6261 todoInput . value = ""
63- ul . innerHTML += `
62+ const setId = new Date ( ) . getTime ( )
63+ array . push ( ul . innerHTML += `
6464 <li class="todo-item">
65- <input id="${ id } " class="inp" value=${ todo } type="text" readonly>
66- <button id="${ id } " class="btn-edit">Edit</button>
67- <button id="${ id } " class="btn-delete">Delete</button>
65+ <input id="${ setId } " class="inp" value=${ todo } type="text" readonly>
66+ <button id="${ setId } " class="btn-edit">Edit</button>
67+ <button id="${ setId } " class="btn-delete">Delete</button>
6868 </li>
69- `
70-
69+ ` )
70+ console . log ( array ) ;
71+
7172 main . appendChild ( ul )
7273}
7374
@@ -76,20 +77,22 @@ ul.addEventListener('click', (e) => {
7677 let inp = todoList . childNodes [ 1 ] . children [ 0 ] . id ;
7778 let btn = e . target . classList . contains ( "btn-edit" )
7879 let moreGet = todoList . childNodes [ 1 ] . children [ 0 ]
79- // console.dir(moreGet );
80+ console . log ( inp ) ;
8081
81- if ( btn ) {
82- if ( e . target . id === inp ) {
83- if ( moreGet . hasAttribute ( 'readonly' ) ) {
84- moreGet . removeAttribute ( 'readonly' )
85- moreGet . style . border = "1px solid blue"
86- } else {
87- moreGet . setAttribute ( 'readonly' , true )
88- moreGet . style . border = ""
89- }
82+ // console.dir(moreGet);
83+
84+ if ( btn ) {
85+ if ( e . target . id === inp ) {
86+ if ( moreGet . hasAttribute ( 'readonly' ) ) {
87+ moreGet . removeAttribute ( 'readonly' )
88+ moreGet . style . border = "1px solid blue"
89+ } else {
90+ moreGet . setAttribute ( 'readonly' , true )
91+ moreGet . style . border = ""
92+ }
9093 }
9194 }
92-
95+
9396
9497} )
9598
0 commit comments