Skip to content

Commit 769f81e

Browse files
committed
📝🤔Todo
1 parent 6849668 commit 769f81e

2 files changed

Lines changed: 53 additions & 6 deletions

File tree

‎Todo/app.js‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const firebaseConfig = {
1313

1414
const app = initializeApp(firebaseConfig);
1515
const db = getFirestore(app);
16-
1716
const todoHandler = document.getElementById('addTodoBtn');
1817
const todoInput = document.getElementById('todoInput');
1918
const 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) {
7069
ul.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

98103
window.addEventListener("DOMContentLoaded", fetching)

‎Todo/style.css‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
display: flex;
7878
justify-content: space-between;
7979
align-items: center;
80-
transition: background 0.3s ease;
80+
transition: background 0.3s ease;
8181
}
8282

8383
.todo-item .btn-edit,
@@ -117,6 +117,48 @@
117117
border: none;
118118
font-size: 16px;
119119
}
120+
120121
.inp:focus {
121122
outline: none;
123+
}
124+
125+
@media (max-width: 480px) {
126+
.input-section {
127+
flex-direction: column;
128+
}
129+
130+
.input-section input,
131+
.input-section button {
132+
width: 100%;
133+
}
134+
135+
.todo-item {
136+
flex-direction: column;
137+
align-items: flex-start;
138+
}
139+
140+
.inp {
141+
width: 100%;
142+
}
143+
144+
.todo-item .btn-edit,
145+
.todo-item .btn-delete {
146+
width: 100%;
147+
margin-left: 0;
148+
margin-top: 5px;
149+
}
150+
}
151+
152+
@media (min-width: 768px) {
153+
.todo-container {
154+
padding: 40px;
155+
}
156+
157+
.input-section input {
158+
font-size: 18px;
159+
}
160+
161+
.input-section button {
162+
font-size: 18px;
163+
}
122164
}

0 commit comments

Comments
 (0)