@@ -13,7 +13,6 @@ const firebaseConfig = {
1313
1414const app = initializeApp ( firebaseConfig ) ;
1515const db = getFirestore ( app ) ;
16-
1716const todoHandler = document . getElementById ( 'addTodoBtn' ) ;
1817const todoInput = document . getElementById ( 'todoInput' ) ;
1918const main = document . getElementById ( 'main' ) ;
@@ -45,8 +44,8 @@ async function fetching() {
4544 const querySnapshot = await getDocs ( collection ( db , 'Todo' ) ) ;
4645 main . innerHTML = ""
4746 querySnapshot . forEach ( ( doc ) => {
48- const getTodo = doc . data ( ) . todo
49- const setId = doc . id
47+ const getTodo = doc . data ( ) . todo ;
48+ const setId = doc . id ;
5049 append ( getTodo , setId )
5150 } ) ;
5251 } catch ( error ) {
@@ -70,7 +69,6 @@ function append(todo, id) {
7069ul . addEventListener ( 'click' , async ( e ) => {
7170 let btn = e . target . classList . contains ( "btn-edit" )
7271 let input = e . target . previousElementSibling ;
73-
7472 if ( btn ) {
7573 if ( input . hasAttribute ( 'readonly' ) ) {
7674 input . removeAttribute ( 'readonly' )
@@ -81,7 +79,6 @@ ul.addEventListener('click', async (e) => {
8179 input . style . border = ""
8280 input . nextElementSibling . innerText = "Edit"
8381 }
84-
8582 let newVal = input . value
8683 let id = input . id
8784 try {
@@ -93,6 +90,14 @@ ul.addEventListener('click', async (e) => {
9390
9491 }
9592 }
93+
94+ const btnDel = e . target . classList . contains ( "btn-delete" )
95+ const id = e . target . parentElement . firstElementChild . id
96+ if ( btnDel ) {
97+ e . target . parentElement . remove ( )
98+ await deleteDoc ( doc ( db , "Todo" , id ) ) ;
99+
100+ }
96101} )
97102
98103window . addEventListener ( "DOMContentLoaded" , fetching )
0 commit comments