MERGE CALENDAR AND NOTES IN ONE - WHEN NOTE IS ADDED - PUT IT IN THE DATE IN CALENDAR WHEN IT IS ADDED (REMAIN THERE) - Follow Up Deployment
Browse files- index.html +36 -43
index.html
CHANGED
|
@@ -22,7 +22,7 @@
|
|
| 22 |
</div>
|
| 23 |
<div class="flex mt-4 border-b border-gray-200 dark:border-gray-700">
|
| 24 |
<button id="tasks-tab" class="tab-button active px-4 py-2 font-medium text-blue-600 dark:text-blue-400 border-b-2 border-blue-500">Tasks</button>
|
| 25 |
-
<button id="calendar-tab" class="tab-button px-4 py-2 font-medium text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300">Calendar
|
| 26 |
</div>
|
| 27 |
</header>
|
| 28 |
|
|
@@ -33,7 +33,7 @@
|
|
| 33 |
<ul id="tasks-list" class="space-y-3"></ul>
|
| 34 |
</div>
|
| 35 |
|
| 36 |
-
<!-- Calendar
|
| 37 |
<div id="calendar-section" class="tab-content hidden">
|
| 38 |
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-4 mb-4">
|
| 39 |
<div id="calendar-header" class="flex justify-between items-center mb-4">
|
|
@@ -146,6 +146,11 @@
|
|
| 146 |
|
| 147 |
renderCalendar();
|
| 148 |
feather.replace();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
}
|
| 150 |
</script>
|
| 151 |
|
|
@@ -172,7 +177,6 @@
|
|
| 172 |
window.unsubscribeCalendar = null;
|
| 173 |
|
| 174 |
const tasksList = document.getElementById('tasks-list');
|
| 175 |
-
const notesList = document.getElementById('notes-list');
|
| 176 |
const noteInput = document.getElementById('note-input');
|
| 177 |
const addNoteBtn = document.getElementById('add-note');
|
| 178 |
const connectionStatus = document.getElementById('connection-status');
|
|
@@ -200,38 +204,33 @@
|
|
| 200 |
window.addEventListener("offline", () => setStatus(false));
|
| 201 |
setStatus(navigator.onLine);
|
| 202 |
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
text,
|
| 214 |
-
userName,
|
| 215 |
-
createdAt: serverTimestamp(),
|
| 216 |
-
date: dateStr
|
| 217 |
-
};
|
| 218 |
-
|
| 219 |
-
if (activeTab === 'tasks') {
|
| 220 |
-
noteData.type = 'tasks';
|
| 221 |
-
noteData.done = false; // tasks start unchecked
|
| 222 |
-
} else {
|
| 223 |
-
noteData.type = 'calendar';
|
| 224 |
-
}
|
| 225 |
-
|
| 226 |
-
try {
|
| 227 |
-
await addDoc(collection(db, "notes"), noteData);
|
| 228 |
-
noteInput.value = '';
|
| 229 |
-
} catch (err) {
|
| 230 |
-
console.error("Error adding note:", err);
|
| 231 |
-
alert("Failed to add note.");
|
| 232 |
-
}
|
| 233 |
-
}
|
| 234 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
addNoteBtn.addEventListener('click', addNote);
|
| 237 |
noteInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') addNote(); });
|
|
@@ -241,21 +240,14 @@
|
|
| 241 |
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";
|
| 242 |
li.innerHTML = `
|
| 243 |
<div class="flex items-center flex-1">
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
<span class="note-text ${note.done ? "line-through text-gray-400 dark:text-gray-500" : ""}">${note.text}</span>
|
| 247 |
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">Added by ${note.userName || 'Anonymous'}</div>
|
| 248 |
</div>
|
| 249 |
</div>
|
| 250 |
<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">
|
| 251 |
<i data-feather="trash-2" class="w-4 h-4"></i>
|
| 252 |
</button>`;
|
| 253 |
-
if (note.type === 'tasks') {
|
| 254 |
-
li.querySelector(".done-checkbox").addEventListener("change", async (e) => {
|
| 255 |
-
try { await updateDoc(doc(db, "notes", note.id), { done: e.target.checked }); }
|
| 256 |
-
catch (err) { console.error("Error updating note:", err); }
|
| 257 |
-
});
|
| 258 |
-
}
|
| 259 |
li.querySelector(".delete-btn").addEventListener("click", async () => {
|
| 260 |
try { await deleteDoc(doc(db, "notes", note.id)); }
|
| 261 |
catch (err) { console.error("Error deleting note:", err); }
|
|
@@ -292,6 +284,7 @@
|
|
| 292 |
|
| 293 |
const q = query(
|
| 294 |
collection(db, "notes"),
|
|
|
|
| 295 |
where("date", "==", dateStr),
|
| 296 |
orderBy("createdAt","asc")
|
| 297 |
);
|
|
|
|
| 22 |
</div>
|
| 23 |
<div class="flex mt-4 border-b border-gray-200 dark:border-gray-700">
|
| 24 |
<button id="tasks-tab" class="tab-button active px-4 py-2 font-medium text-blue-600 dark:text-blue-400 border-b-2 border-blue-500">Tasks</button>
|
| 25 |
+
<button id="calendar-tab" class="tab-button px-4 py-2 font-medium text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300">Calendar</button>
|
| 26 |
</div>
|
| 27 |
</header>
|
| 28 |
|
|
|
|
| 33 |
<ul id="tasks-list" class="space-y-3"></ul>
|
| 34 |
</div>
|
| 35 |
|
| 36 |
+
<!-- Calendar Section -->
|
| 37 |
<div id="calendar-section" class="tab-content hidden">
|
| 38 |
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-4 mb-4">
|
| 39 |
<div id="calendar-header" class="flex justify-between items-center mb-4">
|
|
|
|
| 146 |
|
| 147 |
renderCalendar();
|
| 148 |
feather.replace();
|
| 149 |
+
|
| 150 |
+
// Select today by default
|
| 151 |
+
const todayStr = new Date().toISOString().split('T')[0];
|
| 152 |
+
window.selectedDateStr = todayStr;
|
| 153 |
+
loadDateNotes(todayStr);
|
| 154 |
}
|
| 155 |
</script>
|
| 156 |
|
|
|
|
| 177 |
window.unsubscribeCalendar = null;
|
| 178 |
|
| 179 |
const tasksList = document.getElementById('tasks-list');
|
|
|
|
| 180 |
const noteInput = document.getElementById('note-input');
|
| 181 |
const addNoteBtn = document.getElementById('add-note');
|
| 182 |
const connectionStatus = document.getElementById('connection-status');
|
|
|
|
| 204 |
window.addEventListener("offline", () => setStatus(false));
|
| 205 |
setStatus(navigator.onLine);
|
| 206 |
|
| 207 |
+
async function addNote() {
|
| 208 |
+
const text = noteInput.value.trim();
|
| 209 |
+
const userName = localStorage.getItem('sharedNotesUserName') || userNameInput.value.trim();
|
| 210 |
+
const dateStr = window.selectedDateStr;
|
| 211 |
+
|
| 212 |
+
if (!text || !userName) return;
|
| 213 |
+
if (!dateStr) {
|
| 214 |
+
alert("Please select a date first!");
|
| 215 |
+
return;
|
| 216 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
+
const noteData = {
|
| 219 |
+
text,
|
| 220 |
+
userName,
|
| 221 |
+
date: dateStr,
|
| 222 |
+
type: 'calendar',
|
| 223 |
+
createdAt: serverTimestamp()
|
| 224 |
+
};
|
| 225 |
+
|
| 226 |
+
try {
|
| 227 |
+
await addDoc(collection(db, "notes"), noteData);
|
| 228 |
+
noteInput.value = '';
|
| 229 |
+
} catch (err) {
|
| 230 |
+
console.error("Error adding note:", err);
|
| 231 |
+
alert("Failed to add note.");
|
| 232 |
+
}
|
| 233 |
+
}
|
| 234 |
|
| 235 |
addNoteBtn.addEventListener('click', addNote);
|
| 236 |
noteInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') addNote(); });
|
|
|
|
| 240 |
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";
|
| 241 |
li.innerHTML = `
|
| 242 |
<div class="flex items-center flex-1">
|
| 243 |
+
<div class="w-full">
|
| 244 |
+
<span class="note-text">${note.text}</span>
|
|
|
|
| 245 |
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">Added by ${note.userName || 'Anonymous'}</div>
|
| 246 |
</div>
|
| 247 |
</div>
|
| 248 |
<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">
|
| 249 |
<i data-feather="trash-2" class="w-4 h-4"></i>
|
| 250 |
</button>`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
li.querySelector(".delete-btn").addEventListener("click", async () => {
|
| 252 |
try { await deleteDoc(doc(db, "notes", note.id)); }
|
| 253 |
catch (err) { console.error("Error deleting note:", err); }
|
|
|
|
| 284 |
|
| 285 |
const q = query(
|
| 286 |
collection(db, "notes"),
|
| 287 |
+
where("type", "==", "calendar"),
|
| 288 |
where("date", "==", dateStr),
|
| 289 |
orderBy("createdAt","asc")
|
| 290 |
);
|