trenesky commited on
Commit
e1bfecc
·
verified ·
1 Parent(s): 5083ee2

when note is added, should have checkbox is is done or not, also should stay remembered, not to dissapier when refresh page - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +29 -1
index.html CHANGED
@@ -144,7 +144,13 @@
144
  const li = document.createElement('li');
145
  li.className = 'note-item group flex items-center justify-between p-4 text-lg bg-gray-50 dark:bg-gray-700 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors duration-200';
146
  li.innerHTML = `
147
- <span class="text-gray-800 dark:text-gray-200">${note.text}</span>
 
 
 
 
 
 
148
  <button
149
  data-id="${note.id}"
150
  class="delete-btn opacity-0 group-hover:opacity-100 text-red-500 hover:text-red-700 dark:hover:text-red-400 transition-opacity duration-200"
@@ -167,6 +173,7 @@
167
  notes.push({
168
  id: doc.id,
169
  text: doc.data().text,
 
170
  createdAt: doc.data().createdAt || new Date()
171
  });
172
  });
@@ -185,6 +192,7 @@
185
  if (text) {
186
  db.collection('notes').add({
187
  text: text,
 
188
  createdAt: firebase.firestore.FieldValue.serverTimestamp()
189
  })
190
  .then(() => {
@@ -210,6 +218,18 @@
210
  });
211
  }
212
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  // Update sync time display
214
  function updateSyncTime() {
215
  lastSyncEl.textContent = `Last synced: ${formatTime(lastSync)}`;
@@ -243,6 +263,7 @@
243
  noteInput.addEventListener('keypress', (e) => {
244
  if (e.key === 'Enter') addNote();
245
  });
 
246
  notesList.addEventListener('click', (e) => {
247
  if (e.target.closest('.delete-btn')) {
248
  const id = e.target.closest('.delete-btn').dataset.id;
@@ -250,6 +271,13 @@
250
  }
251
  });
252
 
 
 
 
 
 
 
 
253
  // Network status listeners
254
  window.addEventListener("offline", setDisconnected);
255
  window.addEventListener("online", setConnected);
 
144
  const li = document.createElement('li');
145
  li.className = 'note-item group flex items-center justify-between p-4 text-lg bg-gray-50 dark:bg-gray-700 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors duration-200';
146
  li.innerHTML = `
147
+ <div class="flex items-center gap-3 flex-1">
148
+ <input type="checkbox" data-id="${note.id}" class="done-checkbox w-5 h-5 text-primary-500 rounded focus:ring-primary-500"
149
+ ${note.done ? 'checked' : ''}>
150
+ <span class="note-text ${note.done ? 'line-through text-gray-400 dark:text-gray-500' : 'text-gray-800 dark:text-gray-200'}">
151
+ ${note.text}
152
+ </span>
153
+ </div>
154
  <button
155
  data-id="${note.id}"
156
  class="delete-btn opacity-0 group-hover:opacity-100 text-red-500 hover:text-red-700 dark:hover:text-red-400 transition-opacity duration-200"
 
173
  notes.push({
174
  id: doc.id,
175
  text: doc.data().text,
176
+ done: doc.data().done || false,
177
  createdAt: doc.data().createdAt || new Date()
178
  });
179
  });
 
192
  if (text) {
193
  db.collection('notes').add({
194
  text: text,
195
+ done: false,
196
  createdAt: firebase.firestore.FieldValue.serverTimestamp()
197
  })
198
  .then(() => {
 
218
  });
219
  }
220
 
221
+ // Toggle "done" state
222
+ function toggleDone(id, checked) {
223
+ db.collection('notes').doc(id).update({ done: checked })
224
+ .then(() => {
225
+ lastSync = new Date();
226
+ updateSyncTime();
227
+ })
228
+ .catch((error) => {
229
+ console.error("Error updating note:", error);
230
+ });
231
+ }
232
+
233
  // Update sync time display
234
  function updateSyncTime() {
235
  lastSyncEl.textContent = `Last synced: ${formatTime(lastSync)}`;
 
263
  noteInput.addEventListener('keypress', (e) => {
264
  if (e.key === 'Enter') addNote();
265
  });
266
+
267
  notesList.addEventListener('click', (e) => {
268
  if (e.target.closest('.delete-btn')) {
269
  const id = e.target.closest('.delete-btn').dataset.id;
 
271
  }
272
  });
273
 
274
+ notesList.addEventListener('change', (e) => {
275
+ if (e.target.classList.contains('done-checkbox')) {
276
+ const id = e.target.dataset.id;
277
+ toggleDone(id, e.target.checked);
278
+ }
279
+ });
280
+
281
  // Network status listeners
282
  window.addEventListener("offline", setDisconnected);
283
  window.addEventListener("online", setConnected);