trenesky commited on
Commit
41de9fd
·
verified ·
1 Parent(s): d24c82d

remove calendar dates notes - remain simple as it is for tasks only - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +158 -107
index.html CHANGED
@@ -16,13 +16,10 @@
16
  <!-- Header -->
17
  <header class="p-4 bg-white dark:bg-gray-800 shadow-md flex flex-col gap-2 sticky top-0 z-10 safe-area-top">
18
  <h1 class="text-2xl font-bold bg-gradient-to-r from-blue-500 to-purple-600 bg-clip-text text-transparent">NoteSync</h1>
19
-
20
- <!-- Tabs -->
21
  <div class="flex gap-2">
22
  <button id="tab-tasks" class="flex-1 py-2 rounded-lg bg-blue-500 text-white font-semibold hover:opacity-90 transition">Tasks</button>
23
  <button id="tab-notes" class="flex-1 py-2 rounded-lg bg-gray-300 dark:bg-gray-700 text-gray-800 dark:text-gray-100 font-semibold hover:opacity-90 transition">Notes</button>
24
  </div>
25
-
26
  <span id="connection-status" class="flex items-center gap-2 text-sm px-3 py-1 rounded-full bg-gray-100 dark:bg-gray-700 w-max">
27
  <span class="w-2 h-2 rounded-full bg-gray-400"></span>
28
  <span>Connecting...</span>
@@ -47,12 +44,12 @@
47
  <footer id="footer-input" class="p-4 bg-white dark:bg-gray-800 shadow-md sticky bottom-0 safe-area-bottom hidden">
48
  <div class="max-w-2xl mx-auto">
49
  <div class="flex mb-2" id="name-input-container" style="display:none;">
50
- <input id="user-name" type="text" placeholder="Your name"
51
  class="flex-1 p-3 rounded-lg bg-gray-100 dark:bg-gray-700 border-none outline-none focus:ring-2 focus:ring-blue-500 transition text-base"
52
  autocomplete="name" autocorrect="off" spellcheck="false" />
53
  </div>
54
  <div class="flex">
55
- <input id="item-input" type="text" placeholder="Write something..."
56
  class="flex-1 p-3 rounded-l-lg bg-gray-100 dark:bg-gray-700 border-none outline-none focus:ring-2 focus:ring-blue-500 transition text-base"
57
  autocomplete="off" autocorrect="off" spellcheck="false" />
58
  <button id="add-item" class="px-6 bg-gradient-to-r from-blue-500 to-purple-600 text-white rounded-r-lg hover:opacity-90 transition active:scale-95">
@@ -65,13 +62,12 @@
65
  <!-- Firebase & Script -->
66
  <script type="module">
67
  import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js";
68
- import { getFirestore, collection, addDoc, onSnapshot, serverTimestamp, orderBy, doc, deleteDoc, updateDoc, where, query }
69
  from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js";
70
  import { getAuth, signInWithEmailAndPassword, createUserWithEmailAndPassword, onAuthStateChanged }
71
  from "https://www.gstatic.com/firebasejs/10.12.2/firebase-auth.js";
72
  import { enableIndexedDbPersistence } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js";
73
 
74
- // Firebase config
75
  const firebaseConfig = {
76
  apiKey: "AIzaSyBB4nUHIYHAxzXbRBslGf9nAuqbTNBcslw",
77
  authDomain: "mynotes-3a0a3.firebaseapp.com",
@@ -80,19 +76,15 @@
80
  messagingSenderId: "168872894321",
81
  appId: "1:168872894321:web:81be345db5143cf1f2a0d0"
82
  };
 
83
  const app = initializeApp(firebaseConfig);
84
  const db = getFirestore(app);
85
  const auth = getAuth(app);
86
 
87
- enableIndexedDbPersistence(db)
88
- .then(() => console.log("Firebase offline persistence enabled"))
89
- .catch(err => {
90
- if (err.code === 'failed-precondition') {
91
- console.warn("Multiple tabs open, persistence can only be enabled in one tab at a time.");
92
- } else if (err.code === 'unimplemented') {
93
- console.warn("Persistence is not available in this browser.");
94
- }
95
- });
96
 
97
  // DOM elements
98
  const loginContainer = document.getElementById('login-container');
@@ -124,94 +116,99 @@
124
  loginBtn.addEventListener('click', async () => {
125
  const email = emailInput.value.trim();
126
  const password = passwordInput.value.trim();
127
- if (!email || !password) return;
128
- try {
129
- await signInWithEmailAndPassword(auth, email, password);
130
- } catch (err) {
131
- if (err.code === 'auth/user-not-found') {
132
- try { await createUserWithEmailAndPassword(auth, email, password); }
133
- catch (err2) { console.error(err2); alert(err2.message); }
134
  } else { console.error(err); alert(err.message); }
135
  }
136
  });
137
 
138
- onAuthStateChanged(auth, user => {
139
- if (user) {
140
- console.log("Logged in as", user.email);
141
- loginContainer.style.display = 'none';
142
  mainContent.classList.remove('hidden');
143
  footerInput.classList.remove('hidden');
144
- loadItems(currentTab);
145
  } else {
146
- loginContainer.style.display = 'block';
147
  mainContent.classList.add('hidden');
148
  footerInput.classList.add('hidden');
149
  }
150
  });
151
 
152
  // Add item
153
- async function addItem() {
154
- const text = itemInput.value.trim();
155
- const user = auth.currentUser;
156
- const userName = user ? user.email : 'Anonymous';
157
- if (!text) return;
158
-
159
- try {
160
- await addDoc(collection(db, "notes"), {
 
 
 
 
 
 
161
  text,
162
  userName,
163
  createdAt: serverTimestamp(),
164
  type: currentTab,
165
- done: currentTab === 'tasks' ? false : null
 
166
  });
167
- itemInput.value = '';
168
- } catch (err) {
169
- console.error("Error adding item:", err);
170
  alert("Failed to add item.");
171
  }
172
  }
 
173
  addItemBtn.addEventListener('click', addItem);
174
- itemInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') addItem(); });
175
-
176
- // Render item (tasks & notes)
177
- function renderItem(item) {
178
- const li = document.createElement("li");
179
- li.className = "note-item flex items-center justify-between p-4 bg-white dark:bg-gray-800 rounded-lg shadow-sm hover:shadow-md transition-all group";
180
-
181
- let dateText = "";
182
- if (item.createdAt && item.createdAt.toDate) {
183
- const d = item.createdAt.toDate();
184
- const day = String(d.getDate()).padStart(2, "0");
185
- const month = String(d.getMonth() + 1).padStart(2, "0");
186
- const year = d.getFullYear();
187
- dateText = `${day}-${month}-${year}`;
 
 
188
  }
189
 
190
- if (item.type === 'tasks') {
191
- li.innerHTML = `
192
  <div class="flex items-center flex-1">
193
- <input type="checkbox" class="done-checkbox w-5 h-5 mr-3 rounded border-gray-300 text-blue-600 focus:ring-blue-500" ${item.done ? "checked" : ""}>
194
  <div class="w-[calc(100%-2rem)]">
195
- <span class="note-text ${item.done ? "line-through text-gray-400 dark:text-gray-500" : ""}">${item.text}</span>
196
- <div class="text-xs text-gray-500 dark:text-gray-400 mt-1">
197
- Added by ${item.userName || 'Anonymous'} on ${dateText || '...'}
198
- </div>
199
  </div>
200
  </div>
201
  <button class="delete-btn p-2 text-red-500 hover:bg-red-50 dark:hover:bg-gray-700 rounded-full opacity-100 md:opacity-0 md:group-hover:opacity-100 transition active:scale-95">
202
  <i data-feather="trash-2" class="w-4 h-4"></i>
203
- </button>`;
204
- li.querySelector(".done-checkbox").addEventListener("change", async (e) => {
205
- try { await updateDoc(doc(db, "notes", item.id), { done: e.target.checked }); }
206
- catch (err) { console.error("Error updating task:", err); }
 
207
  });
208
  } else {
209
- li.innerHTML = `
210
  <div class="flex-1">
211
  <span class="note-text">${item.text}</span>
212
- <div class="text-xs text-gray-500 dark:text-gray-400 mt-1">
213
- Added by ${item.userName || 'Anonymous'} on ${dateText || '...'}
214
- </div>
215
  </div>
216
  <div class="flex gap-2">
217
  <button class="edit-btn p-2 text-blue-500 hover:bg-blue-50 dark:hover:bg-gray-700 rounded-full transition active:scale-95">
@@ -220,79 +217,133 @@
220
  <button class="delete-btn p-2 text-red-500 hover:bg-red-50 dark:hover:bg-gray-700 rounded-full transition active:scale-95">
221
  <i data-feather="trash-2" class="w-4 h-4"></i>
222
  </button>
223
- </div>`;
224
- li.querySelector(".edit-btn").addEventListener("click", () => {
 
225
  const textSpan = li.querySelector(".note-text");
226
  const input = document.createElement("input");
227
- input.type = "text";
228
- input.value = textSpan.textContent;
229
- input.className = "w-full p-1 rounded bg-gray-100 dark:bg-gray-700 border border-gray-300 dark:border-gray-600 focus:outline-none focus:ring-2 focus:ring-blue-500";
230
  textSpan.replaceWith(input);
231
  input.focus();
232
- const saveEdit = async () => {
233
- const newText = input.value.trim();
234
- if (newText && newText !== item.text) {
235
- try { await updateDoc(doc(db, "notes", item.id), { text: newText }); }
236
- catch (err) { console.error("Error updating note:", err); }
237
  }
238
  input.replaceWith(textSpan);
239
- textSpan.textContent = newText || item.text;
240
  };
241
  input.addEventListener("blur", saveEdit);
242
- input.addEventListener("keypress", (e) => { if (e.key === "Enter") saveEdit(); });
243
  });
244
  }
245
 
246
- li.querySelector(".delete-btn").addEventListener("click", async () => {
247
- try { await deleteDoc(doc(db, "notes", item.id)); }
248
- catch (err) { console.error("Error deleting item:", err); }
249
  });
250
 
251
  itemsList.appendChild(li);
252
  }
253
 
254
  // Load items
255
- function loadItems(type) {
256
- itemsList.innerHTML = '<div class="text-center py-8"><div class="inline-block animate-spin h-8 w-8 border-t-2 border-b-2 border-blue-500 rounded-full"></div><p class="mt-2 text-gray-500">Loading...</p></div>';
257
- const q = query(collection(db, "notes"), where("type","==",type), orderBy("createdAt","asc"));
258
- onSnapshot(q, (snapshot) => {
259
- itemsList.innerHTML = "";
260
- if (snapshot.empty) {
261
- itemsList.innerHTML = `<div class="text-center py-8"><i data-feather="check-circle" class="w-12 h-12 mx-auto text-gray-400"></i><p class="mt-2 text-gray-500">No ${type} yet.</p></div>`;
262
  feather.replace();
263
  return;
264
  }
265
- snapshot.forEach(docSnap => renderItem({ id: docSnap.id, ...docSnap.data() }));
266
  feather.replace();
 
 
 
 
 
 
 
 
 
 
 
 
267
  });
268
  }
269
 
270
- // Tab switching
271
- tabTasks.addEventListener('click', () => {
272
- currentTab = 'tasks';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
  tabTasks.classList.add('bg-blue-500','text-white');
274
  tabTasks.classList.remove('bg-gray-300','dark:bg-gray-700','text-gray-800','dark:text-gray-100');
275
  tabNotes.classList.add('bg-gray-300','dark:bg-gray-700','text-gray-800','dark:text-gray-100');
276
  tabNotes.classList.remove('bg-blue-500','text-white');
277
- loadItems(currentTab);
278
  });
279
- tabNotes.addEventListener('click', () => {
280
- currentTab = 'notes';
 
281
  tabNotes.classList.add('bg-blue-500','text-white');
282
  tabNotes.classList.remove('bg-gray-300','dark:bg-gray-700','text-gray-800','dark:text-gray-100');
283
  tabTasks.classList.add('bg-gray-300','dark:bg-gray-700','text-gray-800','dark:text-gray-100');
284
  tabTasks.classList.remove('bg-blue-500','text-white');
285
- loadItems(currentTab);
286
  });
287
 
288
- // Default tab
289
- loadItems(currentTab);
290
-
291
  // PWA service worker
292
- if ('serviceWorker' in navigator) {
293
- navigator.serviceWorker.register('sw.js')
294
- .then(() => console.log('Service Worker Registered'))
295
- .catch(err => console.error('Service Worker registration failed:', err));
296
  }
297
  </script>
298
  </body>
 
16
  <!-- Header -->
17
  <header class="p-4 bg-white dark:bg-gray-800 shadow-md flex flex-col gap-2 sticky top-0 z-10 safe-area-top">
18
  <h1 class="text-2xl font-bold bg-gradient-to-r from-blue-500 to-purple-600 bg-clip-text text-transparent">NoteSync</h1>
 
 
19
  <div class="flex gap-2">
20
  <button id="tab-tasks" class="flex-1 py-2 rounded-lg bg-blue-500 text-white font-semibold hover:opacity-90 transition">Tasks</button>
21
  <button id="tab-notes" class="flex-1 py-2 rounded-lg bg-gray-300 dark:bg-gray-700 text-gray-800 dark:text-gray-100 font-semibold hover:opacity-90 transition">Notes</button>
22
  </div>
 
23
  <span id="connection-status" class="flex items-center gap-2 text-sm px-3 py-1 rounded-full bg-gray-100 dark:bg-gray-700 w-max">
24
  <span class="w-2 h-2 rounded-full bg-gray-400"></span>
25
  <span>Connecting...</span>
 
44
  <footer id="footer-input" class="p-4 bg-white dark:bg-gray-800 shadow-md sticky bottom-0 safe-area-bottom hidden">
45
  <div class="max-w-2xl mx-auto">
46
  <div class="flex mb-2" id="name-input-container" style="display:none;">
47
+ <input id="user-name" type="text" placeholder="Your name"
48
  class="flex-1 p-3 rounded-lg bg-gray-100 dark:bg-gray-700 border-none outline-none focus:ring-2 focus:ring-blue-500 transition text-base"
49
  autocomplete="name" autocorrect="off" spellcheck="false" />
50
  </div>
51
  <div class="flex">
52
+ <input id="item-input" type="text" placeholder="Write something..."
53
  class="flex-1 p-3 rounded-l-lg bg-gray-100 dark:bg-gray-700 border-none outline-none focus:ring-2 focus:ring-blue-500 transition text-base"
54
  autocomplete="off" autocorrect="off" spellcheck="false" />
55
  <button id="add-item" class="px-6 bg-gradient-to-r from-blue-500 to-purple-600 text-white rounded-r-lg hover:opacity-90 transition active:scale-95">
 
62
  <!-- Firebase & Script -->
63
  <script type="module">
64
  import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js";
65
+ import { getFirestore, collection, addDoc, onSnapshot, serverTimestamp, orderBy, doc, deleteDoc, updateDoc, where, query, getDocs }
66
  from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js";
67
  import { getAuth, signInWithEmailAndPassword, createUserWithEmailAndPassword, onAuthStateChanged }
68
  from "https://www.gstatic.com/firebasejs/10.12.2/firebase-auth.js";
69
  import { enableIndexedDbPersistence } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js";
70
 
 
71
  const firebaseConfig = {
72
  apiKey: "AIzaSyBB4nUHIYHAxzXbRBslGf9nAuqbTNBcslw",
73
  authDomain: "mynotes-3a0a3.firebaseapp.com",
 
76
  messagingSenderId: "168872894321",
77
  appId: "1:168872894321:web:81be345db5143cf1f2a0d0"
78
  };
79
+
80
  const app = initializeApp(firebaseConfig);
81
  const db = getFirestore(app);
82
  const auth = getAuth(app);
83
 
84
+ enableIndexedDbPersistence(db).catch(err => {
85
+ if(err.code === 'failed-precondition') console.warn("Multiple tabs open, persistence can only be enabled in one tab at a time.");
86
+ else if(err.code === 'unimplemented') console.warn("Persistence is not available in this browser.");
87
+ });
 
 
 
 
 
88
 
89
  // DOM elements
90
  const loginContainer = document.getElementById('login-container');
 
116
  loginBtn.addEventListener('click', async () => {
117
  const email = emailInput.value.trim();
118
  const password = passwordInput.value.trim();
119
+ if(!email || !password) return;
120
+ try { await signInWithEmailAndPassword(auth,email,password); }
121
+ catch(err){
122
+ if(err.code==='auth/user-not-found'){
123
+ try { await createUserWithEmailAndPassword(auth,email,password); }
124
+ catch(err2){ console.error(err2); alert(err2.message); }
 
125
  } else { console.error(err); alert(err.message); }
126
  }
127
  });
128
 
129
+ onAuthStateChanged(auth,user=>{
130
+ if(user){
131
+ loginContainer.style.display='none';
 
132
  mainContent.classList.remove('hidden');
133
  footerInput.classList.remove('hidden');
134
+ initializePositions(currentTab).then(()=>loadItems(currentTab));
135
  } else {
136
+ loginContainer.style.display='block';
137
  mainContent.classList.add('hidden');
138
  footerInput.classList.add('hidden');
139
  }
140
  });
141
 
142
  // Add item
143
+ async function addItem(){
144
+ const text=itemInput.value.trim();
145
+ const user=auth.currentUser;
146
+ const userName=user? user.email:'Anonymous';
147
+ if(!text) return;
148
+
149
+ try{
150
+ // Find max position
151
+ const snapshot = await getDocs(query(collection(db,'notes'),where('type','==',currentTab)));
152
+ let maxPos = -1;
153
+ snapshot.forEach(docSnap=>{
154
+ if(docSnap.data().position!==undefined && docSnap.data().position>maxPos) maxPos=docSnap.data().position;
155
+ });
156
+ await addDoc(collection(db,'notes'),{
157
  text,
158
  userName,
159
  createdAt: serverTimestamp(),
160
  type: currentTab,
161
+ done: currentTab==='tasks'?false:null,
162
+ position: maxPos+1
163
  });
164
+ itemInput.value='';
165
+ } catch(err){
166
+ console.error("Error adding item:",err);
167
  alert("Failed to add item.");
168
  }
169
  }
170
+
171
  addItemBtn.addEventListener('click', addItem);
172
+ itemInput.addEventListener('keypress', e=>{if(e.key==='Enter') addItem();});
173
+
174
+ // Render item
175
+ function renderItem(item){
176
+ const li=document.createElement('li');
177
+ li.className='note-item flex items-center justify-between p-4 bg-white dark:bg-gray-800 rounded-lg shadow-sm hover:shadow-md transition-all group';
178
+ li.setAttribute('draggable','true');
179
+ li.dataset.id=item.id;
180
+
181
+ let dateText='';
182
+ if(item.createdAt && item.createdAt.toDate){
183
+ const d=item.createdAt.toDate();
184
+ const day=String(d.getDate()).padStart(2,'0');
185
+ const month=String(d.getMonth()+1).padStart(2,'0');
186
+ const year=d.getFullYear();
187
+ dateText=`${day}-${month}-${year}`;
188
  }
189
 
190
+ if(item.type==='tasks'){
191
+ li.innerHTML=`
192
  <div class="flex items-center flex-1">
193
+ <input type="checkbox" class="done-checkbox w-5 h-5 mr-3 rounded border-gray-300 text-blue-600 focus:ring-blue-500" ${item.done?'checked':''}>
194
  <div class="w-[calc(100%-2rem)]">
195
+ <span class="note-text ${item.done?"line-through text-gray-400 dark:text-gray-500":""}">${item.text}</span>
196
+ <div class="text-xs text-gray-500 dark:text-gray-400 mt-1">Added by ${item.userName||'Anonymous'} on ${dateText||'...'}</div>
 
 
197
  </div>
198
  </div>
199
  <button class="delete-btn p-2 text-red-500 hover:bg-red-50 dark:hover:bg-gray-700 rounded-full opacity-100 md:opacity-0 md:group-hover:opacity-100 transition active:scale-95">
200
  <i data-feather="trash-2" class="w-4 h-4"></i>
201
+ </button>
202
+ `;
203
+ li.querySelector(".done-checkbox").addEventListener("change", async e=>{
204
+ try{ await updateDoc(doc(db,'notes',item.id),{done:e.target.checked}); }
205
+ catch(err){ console.error(err); }
206
  });
207
  } else {
208
+ li.innerHTML=`
209
  <div class="flex-1">
210
  <span class="note-text">${item.text}</span>
211
+ <div class="text-xs text-gray-500 dark:text-gray-400 mt-1">Added by ${item.userName||'Anonymous'} on ${dateText||'...'}</div>
 
 
212
  </div>
213
  <div class="flex gap-2">
214
  <button class="edit-btn p-2 text-blue-500 hover:bg-blue-50 dark:hover:bg-gray-700 rounded-full transition active:scale-95">
 
217
  <button class="delete-btn p-2 text-red-500 hover:bg-red-50 dark:hover:bg-gray-700 rounded-full transition active:scale-95">
218
  <i data-feather="trash-2" class="w-4 h-4"></i>
219
  </button>
220
+ </div>
221
+ `;
222
+ li.querySelector(".edit-btn").addEventListener("click", ()=>{
223
  const textSpan = li.querySelector(".note-text");
224
  const input = document.createElement("input");
225
+ input.type="text";
226
+ input.value=textSpan.textContent;
227
+ input.className="w-full p-1 rounded bg-gray-100 dark:bg-gray-700 border border-gray-300 dark:border-gray-600 focus:outline-none focus:ring-2 focus:ring-blue-500";
228
  textSpan.replaceWith(input);
229
  input.focus();
230
+ const saveEdit=async ()=>{
231
+ const newText=input.value.trim();
232
+ if(newText && newText!==item.text){
233
+ try{ await updateDoc(doc(db,'notes',item.id),{text:newText}); }
234
+ catch(err){ console.error(err); }
235
  }
236
  input.replaceWith(textSpan);
237
+ textSpan.textContent=newText||item.text;
238
  };
239
  input.addEventListener("blur", saveEdit);
240
+ input.addEventListener("keypress", e=>{if(e.key==="Enter") saveEdit();});
241
  });
242
  }
243
 
244
+ li.querySelector(".delete-btn").addEventListener("click", async ()=>{
245
+ try{ await deleteDoc(doc(db,'notes',item.id)); }
246
+ catch(err){ console.error(err); }
247
  });
248
 
249
  itemsList.appendChild(li);
250
  }
251
 
252
  // Load items
253
+ function loadItems(type){
254
+ itemsList.innerHTML='<div class="text-center py-8"><div class="inline-block animate-spin h-8 w-8 border-t-2 border-b-2 border-blue-500 rounded-full"></div><p class="mt-2 text-gray-500">Loading...</p></div>';
255
+ const q=query(collection(db,'notes'),where("type","==",type),orderBy("position","asc"),orderBy("createdAt","asc"));
256
+ onSnapshot(q,snapshot=>{
257
+ itemsList.innerHTML='';
258
+ if(snapshot.empty){
259
+ itemsList.innerHTML=`<div class="text-center py-8"><i data-feather="check-circle" class="w-12 h-12 mx-auto text-gray-400"></i><p class="mt-2 text-gray-500">No ${type} yet.</p></div>`;
260
  feather.replace();
261
  return;
262
  }
263
+ snapshot.forEach(docSnap=>renderItem({id:docSnap.id,...docSnap.data()}));
264
  feather.replace();
265
+ enableDragAndDrop();
266
+ });
267
+ }
268
+
269
+ // Initialize positions if missing
270
+ async function initializePositions(type){
271
+ const snapshot = await getDocs(query(collection(db,"notes"),where("type","==",type),orderBy("createdAt","asc")));
272
+ let pos=0;
273
+ snapshot.forEach(async docSnap=>{
274
+ if(docSnap.data().position===undefined){
275
+ await updateDoc(doc(db,"notes",docSnap.id),{position:pos++});
276
+ } else pos=Math.max(pos,docSnap.data().position+1);
277
  });
278
  }
279
 
280
+ // Drag and Drop
281
+ function enableDragAndDrop(){
282
+ let dragSrcEl=null;
283
+
284
+ function handleDragStart(e){
285
+ dragSrcEl=this;
286
+ e.dataTransfer.effectAllowed='move';
287
+ e.dataTransfer.setData('text/html',this.outerHTML);
288
+ this.classList.add('opacity-50');
289
+ }
290
+
291
+ function handleDragOver(e){ e.preventDefault(); e.dataTransfer.dropEffect='move'; return false; }
292
+ function handleDragEnter(){ this.classList.add('bg-gray-200','dark:bg-gray-700'); }
293
+ function handleDragLeave(){ this.classList.remove('bg-gray-200','dark:bg-gray-700'); }
294
+
295
+ async function handleDrop(e){
296
+ e.stopPropagation();
297
+ if(dragSrcEl!==this){
298
+ const parent=dragSrcEl.parentNode;
299
+ parent.insertBefore(dragSrcEl,this.nextSibling);
300
+
301
+ const items=Array.from(itemsList.querySelectorAll('li'));
302
+ for(let i=0;i<items.length;i++){
303
+ const id=items[i].dataset.id;
304
+ await updateDoc(doc(db,'notes',id),{position:i});
305
+ }
306
+ }
307
+ this.classList.remove('bg-gray-200','dark:bg-gray-700');
308
+ dragSrcEl.classList.remove('opacity-50');
309
+ return false;
310
+ }
311
+
312
+ function handleDragEnd(){ this.classList.remove('opacity-50'); itemsList.querySelectorAll('li').forEach(item=>item.classList.remove('bg-gray-200','dark:bg-gray-700')); }
313
+
314
+ const items=itemsList.querySelectorAll('li');
315
+ items.forEach(item=>{
316
+ item.addEventListener('dragstart',handleDragStart);
317
+ item.addEventListener('dragover',handleDragOver);
318
+ item.addEventListener('dragenter',handleDragEnter);
319
+ item.addEventListener('dragleave',handleDragLeave);
320
+ item.addEventListener('drop',handleDrop);
321
+ item.addEventListener('dragend',handleDragEnd);
322
+ });
323
+ }
324
+
325
+ // Tabs
326
+ tabTasks.addEventListener('click',()=>{
327
+ currentTab='tasks';
328
  tabTasks.classList.add('bg-blue-500','text-white');
329
  tabTasks.classList.remove('bg-gray-300','dark:bg-gray-700','text-gray-800','dark:text-gray-100');
330
  tabNotes.classList.add('bg-gray-300','dark:bg-gray-700','text-gray-800','dark:text-gray-100');
331
  tabNotes.classList.remove('bg-blue-500','text-white');
332
+ initializePositions(currentTab).then(()=>loadItems(currentTab));
333
  });
334
+
335
+ tabNotes.addEventListener('click',()=>{
336
+ currentTab='notes';
337
  tabNotes.classList.add('bg-blue-500','text-white');
338
  tabNotes.classList.remove('bg-gray-300','dark:bg-gray-700','text-gray-800','dark:text-gray-100');
339
  tabTasks.classList.add('bg-gray-300','dark:bg-gray-700','text-gray-800','dark:text-gray-100');
340
  tabTasks.classList.remove('bg-blue-500','text-white');
341
+ initializePositions(currentTab).then(()=>loadItems(currentTab));
342
  });
343
 
 
 
 
344
  // PWA service worker
345
+ if('serviceWorker' in navigator){
346
+ navigator.serviceWorker.register('sw.js').then(()=>console.log('Service Worker Registered')).catch(err=>console.error(err));
 
 
347
  }
348
  </script>
349
  </body>