remove calendar dates notes - remain simple as it is for tasks only - Follow Up Deployment
Browse files- index.html +68 -36
index.html
CHANGED
|
@@ -29,17 +29,24 @@
|
|
| 29 |
</span>
|
| 30 |
</header>
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
<!-- Content -->
|
| 33 |
-
<main class="flex-1 p-4 max-w-2xl w-full mx-auto">
|
| 34 |
<ul id="items-list" class="space-y-3">
|
| 35 |
<!-- Tasks or Notes will be loaded here -->
|
| 36 |
</ul>
|
| 37 |
</main>
|
| 38 |
|
| 39 |
<!-- Input -->
|
| 40 |
-
<footer class="p-4 bg-white dark:bg-gray-800 shadow-md sticky bottom-0 safe-area-bottom">
|
| 41 |
<div class="max-w-2xl mx-auto">
|
| 42 |
-
<div class="flex mb-2" id="name-input-container">
|
| 43 |
<input id="user-name" type="text" placeholder="Your name"
|
| 44 |
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"
|
| 45 |
autocomplete="name" autocorrect="off" spellcheck="false" />
|
|
@@ -60,7 +67,11 @@
|
|
| 60 |
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js";
|
| 61 |
import { getFirestore, collection, addDoc, onSnapshot, serverTimestamp, orderBy, doc, deleteDoc, updateDoc, where, query }
|
| 62 |
from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js";
|
|
|
|
|
|
|
|
|
|
| 63 |
|
|
|
|
| 64 |
const firebaseConfig = {
|
| 65 |
apiKey: "AIzaSyBB4nUHIYHAxzXbRBslGf9nAuqbTNBcslw",
|
| 66 |
authDomain: "mynotes-3a0a3.firebaseapp.com",
|
|
@@ -71,42 +82,30 @@
|
|
| 71 |
};
|
| 72 |
const app = initializeApp(firebaseConfig);
|
| 73 |
const db = getFirestore(app);
|
| 74 |
-
|
| 75 |
-
import { enableIndexedDbPersistence } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js";
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
const itemsList = document.getElementById('items-list');
|
| 87 |
const itemInput = document.getElementById('item-input');
|
| 88 |
const addItemBtn = document.getElementById('add-item');
|
| 89 |
const connectionStatus = document.getElementById('connection-status');
|
| 90 |
-
const nameInputContainer = document.getElementById('name-input-container');
|
| 91 |
-
const userNameInput = document.getElementById('user-name');
|
| 92 |
-
|
| 93 |
const tabTasks = document.getElementById('tab-tasks');
|
| 94 |
const tabNotes = document.getElementById('tab-notes');
|
| 95 |
let currentTab = 'tasks';
|
| 96 |
|
| 97 |
-
// Load stored name
|
| 98 |
-
const storedName = localStorage.getItem('sharedNotesUserName');
|
| 99 |
-
if (storedName) {
|
| 100 |
-
nameInputContainer.style.display = 'none';
|
| 101 |
-
userNameInput.value = storedName;
|
| 102 |
-
} else {
|
| 103 |
-
userNameInput.addEventListener('change', () => {
|
| 104 |
-
if (userNameInput.value.trim()) {
|
| 105 |
-
localStorage.setItem('sharedNotesUserName', userNameInput.value.trim());
|
| 106 |
-
}
|
| 107 |
-
});
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
// Connection status
|
| 111 |
function setStatus(online) {
|
| 112 |
connectionStatus.innerHTML = online
|
|
@@ -117,10 +116,44 @@
|
|
| 117 |
window.addEventListener("offline", () => setStatus(false));
|
| 118 |
setStatus(navigator.onLine);
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
// Add item
|
| 121 |
async function addItem() {
|
| 122 |
const text = itemInput.value.trim();
|
| 123 |
-
const
|
|
|
|
| 124 |
if (!text) return;
|
| 125 |
|
| 126 |
try {
|
|
@@ -140,7 +173,7 @@
|
|
| 140 |
addItemBtn.addEventListener('click', addItem);
|
| 141 |
itemInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') addItem(); });
|
| 142 |
|
| 143 |
-
// Render item
|
| 144 |
function renderItem(item) {
|
| 145 |
const li = document.createElement("li");
|
| 146 |
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";
|
|
@@ -172,8 +205,7 @@
|
|
| 172 |
try { await updateDoc(doc(db, "notes", item.id), { done: e.target.checked }); }
|
| 173 |
catch (err) { console.error("Error updating task:", err); }
|
| 174 |
});
|
| 175 |
-
|
| 176 |
-
} else { // notes
|
| 177 |
li.innerHTML = `
|
| 178 |
<div class="flex-1">
|
| 179 |
<span class="note-text">${item.text}</span>
|
|
@@ -253,10 +285,10 @@
|
|
| 253 |
loadItems(currentTab);
|
| 254 |
});
|
| 255 |
|
| 256 |
-
//
|
| 257 |
loadItems(currentTab);
|
| 258 |
|
| 259 |
-
//
|
| 260 |
if ('serviceWorker' in navigator) {
|
| 261 |
navigator.serviceWorker.register('sw.js')
|
| 262 |
.then(() => console.log('Service Worker Registered'))
|
|
|
|
| 29 |
</span>
|
| 30 |
</header>
|
| 31 |
|
| 32 |
+
<!-- Login Form -->
|
| 33 |
+
<div id="login-container" class="max-w-md mx-auto p-4 mt-4 bg-white dark:bg-gray-800 rounded-lg shadow-md">
|
| 34 |
+
<input id="email" type="email" placeholder="Email" class="w-full p-3 mb-2 rounded-lg bg-gray-100 dark:bg-gray-700 border-none outline-none" />
|
| 35 |
+
<input id="password" type="password" placeholder="Password" class="w-full p-3 mb-2 rounded-lg bg-gray-100 dark:bg-gray-700 border-none outline-none" />
|
| 36 |
+
<button id="login-btn" class="w-full py-3 bg-blue-500 text-white rounded-lg hover:opacity-90 transition">Login / Sign Up</button>
|
| 37 |
+
</div>
|
| 38 |
+
|
| 39 |
<!-- Content -->
|
| 40 |
+
<main id="main-content" class="flex-1 p-4 max-w-2xl w-full mx-auto hidden">
|
| 41 |
<ul id="items-list" class="space-y-3">
|
| 42 |
<!-- Tasks or Notes will be loaded here -->
|
| 43 |
</ul>
|
| 44 |
</main>
|
| 45 |
|
| 46 |
<!-- Input -->
|
| 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" />
|
|
|
|
| 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",
|
|
|
|
| 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');
|
| 99 |
+
const mainContent = document.getElementById('main-content');
|
| 100 |
+
const footerInput = document.getElementById('footer-input');
|
| 101 |
const itemsList = document.getElementById('items-list');
|
| 102 |
const itemInput = document.getElementById('item-input');
|
| 103 |
const addItemBtn = document.getElementById('add-item');
|
| 104 |
const connectionStatus = document.getElementById('connection-status');
|
|
|
|
|
|
|
|
|
|
| 105 |
const tabTasks = document.getElementById('tab-tasks');
|
| 106 |
const tabNotes = document.getElementById('tab-notes');
|
| 107 |
let currentTab = 'tasks';
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
// Connection status
|
| 110 |
function setStatus(online) {
|
| 111 |
connectionStatus.innerHTML = online
|
|
|
|
| 116 |
window.addEventListener("offline", () => setStatus(false));
|
| 117 |
setStatus(navigator.onLine);
|
| 118 |
|
| 119 |
+
// Login
|
| 120 |
+
const emailInput = document.getElementById('email');
|
| 121 |
+
const passwordInput = document.getElementById('password');
|
| 122 |
+
const loginBtn = document.getElementById('login-btn');
|
| 123 |
+
|
| 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 {
|
|
|
|
| 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";
|
|
|
|
| 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>
|
|
|
|
| 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'))
|