remove calendar dates notes - remain simple as it is for tasks only - Follow Up Deployment
Browse files- index.html +125 -78
index.html
CHANGED
|
@@ -3,25 +3,32 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover" />
|
| 6 |
-
<title>Shared Tasks App</title>
|
| 7 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 9 |
</head>
|
| 10 |
<body class="bg-gray-100 dark:bg-gray-900 text-gray-900 dark:text-gray-100 min-h-screen flex flex-col">
|
| 11 |
|
| 12 |
<!-- Header -->
|
| 13 |
-
<header class="p-4 bg-white dark:bg-gray-800 shadow-md flex
|
| 14 |
-
<h1 class="text-2xl font-bold bg-gradient-to-r from-blue-500 to-purple-600 bg-clip-text text-transparent">Shared Tasks</h1>
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
<span class="w-2 h-2 rounded-full bg-gray-400"></span>
|
| 17 |
<span>Connecting...</span>
|
| 18 |
</span>
|
| 19 |
</header>
|
| 20 |
|
| 21 |
-
<!--
|
| 22 |
<main class="flex-1 p-4 max-w-2xl w-full mx-auto">
|
| 23 |
-
<ul id="
|
| 24 |
-
<!-- Tasks will be loaded here -->
|
| 25 |
</ul>
|
| 26 |
</main>
|
| 27 |
|
|
@@ -34,20 +41,20 @@
|
|
| 34 |
autocomplete="name" autocorrect="off" spellcheck="false" />
|
| 35 |
</div>
|
| 36 |
<div class="flex">
|
| 37 |
-
<input id="
|
| 38 |
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"
|
| 39 |
autocomplete="off" autocorrect="off" spellcheck="false" />
|
| 40 |
-
<button id="add-
|
| 41 |
<i data-feather="plus" class="w-5 h-5"></i>
|
| 42 |
</button>
|
| 43 |
</div>
|
| 44 |
</div>
|
| 45 |
</footer>
|
| 46 |
|
| 47 |
-
<!-- Firebase &
|
| 48 |
<script type="module">
|
| 49 |
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js";
|
| 50 |
-
import { getFirestore, collection, addDoc, onSnapshot, serverTimestamp, orderBy,
|
| 51 |
from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js";
|
| 52 |
|
| 53 |
const firebaseConfig = {
|
|
@@ -58,17 +65,21 @@
|
|
| 58 |
messagingSenderId: "168872894321",
|
| 59 |
appId: "1:168872894321:web:81be345db5143cf1f2a0d0"
|
| 60 |
};
|
| 61 |
-
|
| 62 |
const app = initializeApp(firebaseConfig);
|
| 63 |
const db = getFirestore(app);
|
| 64 |
|
| 65 |
-
const
|
| 66 |
-
const
|
| 67 |
-
const
|
| 68 |
const connectionStatus = document.getElementById('connection-status');
|
| 69 |
const nameInputContainer = document.getElementById('name-input-container');
|
| 70 |
const userNameInput = document.getElementById('user-name');
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
// Load stored name
|
| 73 |
const storedName = localStorage.getItem('sharedNotesUserName');
|
| 74 |
if (storedName) {
|
|
@@ -92,9 +103,9 @@
|
|
| 92 |
window.addEventListener("offline", () => setStatus(false));
|
| 93 |
setStatus(navigator.onLine);
|
| 94 |
|
| 95 |
-
// Add
|
| 96 |
-
async function
|
| 97 |
-
const text =
|
| 98 |
const userName = localStorage.getItem('sharedNotesUserName') || userNameInput.value.trim();
|
| 99 |
if (!text || !userName) return;
|
| 100 |
|
|
@@ -103,72 +114,108 @@
|
|
| 103 |
text,
|
| 104 |
userName,
|
| 105 |
createdAt: serverTimestamp(),
|
| 106 |
-
type:
|
| 107 |
-
done: false
|
| 108 |
});
|
| 109 |
-
|
| 110 |
} catch (err) {
|
| 111 |
-
console.error("Error adding
|
| 112 |
-
alert("Failed to add
|
| 113 |
}
|
| 114 |
}
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
onSnapshot(tasksQuery, (snapshot) => {
|
| 162 |
-
tasksList.innerHTML = "";
|
| 163 |
-
if (snapshot.empty) {
|
| 164 |
-
tasksList.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 tasks yet.</p></div>';
|
| 165 |
-
feather.replace();
|
| 166 |
-
return;
|
| 167 |
}
|
| 168 |
-
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
});
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
|
|
|
| 173 |
</body>
|
| 174 |
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover" />
|
| 6 |
+
<title>Shared Tasks & Notes App</title>
|
| 7 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 9 |
</head>
|
| 10 |
<body class="bg-gray-100 dark:bg-gray-900 text-gray-900 dark:text-gray-100 min-h-screen flex flex-col">
|
| 11 |
|
| 12 |
<!-- Header -->
|
| 13 |
+
<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">
|
| 14 |
+
<h1 class="text-2xl font-bold bg-gradient-to-r from-blue-500 to-purple-600 bg-clip-text text-transparent">Shared Tasks & Notes</h1>
|
| 15 |
+
|
| 16 |
+
<!-- Tabs -->
|
| 17 |
+
<div class="flex gap-2">
|
| 18 |
+
<button id="tab-tasks" class="flex-1 py-2 rounded-lg bg-blue-500 text-white font-semibold hover:opacity-90 transition">Tasks</button>
|
| 19 |
+
<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>
|
| 20 |
+
</div>
|
| 21 |
+
|
| 22 |
+
<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">
|
| 23 |
<span class="w-2 h-2 rounded-full bg-gray-400"></span>
|
| 24 |
<span>Connecting...</span>
|
| 25 |
</span>
|
| 26 |
</header>
|
| 27 |
|
| 28 |
+
<!-- Content -->
|
| 29 |
<main class="flex-1 p-4 max-w-2xl w-full mx-auto">
|
| 30 |
+
<ul id="items-list" class="space-y-3">
|
| 31 |
+
<!-- Tasks or Notes will be loaded here -->
|
| 32 |
</ul>
|
| 33 |
</main>
|
| 34 |
|
|
|
|
| 41 |
autocomplete="name" autocorrect="off" spellcheck="false" />
|
| 42 |
</div>
|
| 43 |
<div class="flex">
|
| 44 |
+
<input id="item-input" type="text" placeholder="Write something..."
|
| 45 |
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"
|
| 46 |
autocomplete="off" autocorrect="off" spellcheck="false" />
|
| 47 |
+
<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">
|
| 48 |
<i data-feather="plus" class="w-5 h-5"></i>
|
| 49 |
</button>
|
| 50 |
</div>
|
| 51 |
</div>
|
| 52 |
</footer>
|
| 53 |
|
| 54 |
+
<!-- Firebase & Script -->
|
| 55 |
<script type="module">
|
| 56 |
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js";
|
| 57 |
+
import { getFirestore, collection, addDoc, onSnapshot, serverTimestamp, orderBy, doc, deleteDoc, updateDoc, where, query }
|
| 58 |
from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js";
|
| 59 |
|
| 60 |
const firebaseConfig = {
|
|
|
|
| 65 |
messagingSenderId: "168872894321",
|
| 66 |
appId: "1:168872894321:web:81be345db5143cf1f2a0d0"
|
| 67 |
};
|
|
|
|
| 68 |
const app = initializeApp(firebaseConfig);
|
| 69 |
const db = getFirestore(app);
|
| 70 |
|
| 71 |
+
const itemsList = document.getElementById('items-list');
|
| 72 |
+
const itemInput = document.getElementById('item-input');
|
| 73 |
+
const addItemBtn = document.getElementById('add-item');
|
| 74 |
const connectionStatus = document.getElementById('connection-status');
|
| 75 |
const nameInputContainer = document.getElementById('name-input-container');
|
| 76 |
const userNameInput = document.getElementById('user-name');
|
| 77 |
|
| 78 |
+
const tabTasks = document.getElementById('tab-tasks');
|
| 79 |
+
const tabNotes = document.getElementById('tab-notes');
|
| 80 |
+
|
| 81 |
+
let currentTab = 'tasks'; // default
|
| 82 |
+
|
| 83 |
// Load stored name
|
| 84 |
const storedName = localStorage.getItem('sharedNotesUserName');
|
| 85 |
if (storedName) {
|
|
|
|
| 103 |
window.addEventListener("offline", () => setStatus(false));
|
| 104 |
setStatus(navigator.onLine);
|
| 105 |
|
| 106 |
+
// Add item
|
| 107 |
+
async function addItem() {
|
| 108 |
+
const text = itemInput.value.trim();
|
| 109 |
const userName = localStorage.getItem('sharedNotesUserName') || userNameInput.value.trim();
|
| 110 |
if (!text || !userName) return;
|
| 111 |
|
|
|
|
| 114 |
text,
|
| 115 |
userName,
|
| 116 |
createdAt: serverTimestamp(),
|
| 117 |
+
type: currentTab,
|
| 118 |
+
done: currentTab === 'tasks' ? false : undefined
|
| 119 |
});
|
| 120 |
+
itemInput.value = '';
|
| 121 |
} catch (err) {
|
| 122 |
+
console.error("Error adding item:", err);
|
| 123 |
+
alert("Failed to add item.");
|
| 124 |
}
|
| 125 |
}
|
| 126 |
+
addItemBtn.addEventListener('click', addItem);
|
| 127 |
+
itemInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') addItem(); });
|
| 128 |
+
|
| 129 |
+
// Render item
|
| 130 |
+
function renderItem(item) {
|
| 131 |
+
const li = document.createElement("li");
|
| 132 |
+
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";
|
| 133 |
+
|
| 134 |
+
let dateText = "";
|
| 135 |
+
if (item.createdAt && item.createdAt.toDate) {
|
| 136 |
+
const d = item.createdAt.toDate();
|
| 137 |
+
const day = String(d.getDate()).padStart(2, "0");
|
| 138 |
+
const month = String(d.getMonth() + 1).padStart(2, "0");
|
| 139 |
+
const year = d.getFullYear();
|
| 140 |
+
dateText = `${day}-${month}-${year}`;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
if (item.type === 'tasks') {
|
| 144 |
+
li.innerHTML = `
|
| 145 |
+
<div class="flex items-center flex-1">
|
| 146 |
+
<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" : ""}>
|
| 147 |
+
<div class="w-[calc(100%-2rem)]">
|
| 148 |
+
<span class="note-text ${item.done ? "line-through text-gray-400 dark:text-gray-500" : ""}">${item.text}</span>
|
| 149 |
+
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">
|
| 150 |
+
Added by ${item.userName || 'Anonymous'} on ${dateText || '...'}
|
| 151 |
+
</div>
|
| 152 |
+
</div>
|
| 153 |
+
</div>
|
| 154 |
+
<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">
|
| 155 |
+
<i data-feather="trash-2" class="w-4 h-4"></i>
|
| 156 |
+
</button>`;
|
| 157 |
+
li.querySelector(".done-checkbox").addEventListener("change", async (e) => {
|
| 158 |
+
try { await updateDoc(doc(db, "notes", item.id), { done: e.target.checked }); }
|
| 159 |
+
catch (err) { console.error("Error updating task:", err); }
|
| 160 |
+
});
|
| 161 |
+
} else { // notes
|
| 162 |
+
li.innerHTML = `
|
| 163 |
+
<div class="flex-1">
|
| 164 |
+
<span class="note-text">${item.text}</span>
|
| 165 |
+
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">
|
| 166 |
+
Added by ${item.userName || 'Anonymous'} on ${dateText || '...'}
|
| 167 |
+
</div>
|
| 168 |
+
</div>
|
| 169 |
+
<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">
|
| 170 |
+
<i data-feather="trash-2" class="w-4 h-4"></i>
|
| 171 |
+
</button>`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
}
|
| 173 |
+
|
| 174 |
+
li.querySelector(".delete-btn").addEventListener("click", async () => {
|
| 175 |
+
try { await deleteDoc(doc(db, "notes", item.id)); }
|
| 176 |
+
catch (err) { console.error("Error deleting item:", err); }
|
| 177 |
+
});
|
| 178 |
+
|
| 179 |
+
itemsList.appendChild(li);
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
// Load items based on tab
|
| 183 |
+
function loadItems(type) {
|
| 184 |
+
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>';
|
| 185 |
+
const q = query(collection(db, "notes"), where("type","==",type), orderBy("createdAt","asc"));
|
| 186 |
+
onSnapshot(q, (snapshot) => {
|
| 187 |
+
itemsList.innerHTML = "";
|
| 188 |
+
if (snapshot.empty) {
|
| 189 |
+
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>`;
|
| 190 |
+
feather.replace();
|
| 191 |
+
return;
|
| 192 |
+
}
|
| 193 |
+
snapshot.forEach(docSnap => renderItem({ id: docSnap.id, ...docSnap.data() }));
|
| 194 |
+
feather.replace();
|
| 195 |
+
});
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
// Tab switching
|
| 199 |
+
tabTasks.addEventListener('click', () => {
|
| 200 |
+
currentTab = 'tasks';
|
| 201 |
+
tabTasks.classList.add('bg-blue-500', 'text-white');
|
| 202 |
+
tabTasks.classList.remove('bg-gray-300','dark:bg-gray-700','text-gray-800','dark:text-gray-100');
|
| 203 |
+
tabNotes.classList.add('bg-gray-300','dark:bg-gray-700','text-gray-800','dark:text-gray-100');
|
| 204 |
+
tabNotes.classList.remove('bg-blue-500','text-white');
|
| 205 |
+
loadItems(currentTab);
|
| 206 |
});
|
| 207 |
+
tabNotes.addEventListener('click', () => {
|
| 208 |
+
currentTab = 'notes';
|
| 209 |
+
tabNotes.classList.add('bg-blue-500', 'text-white');
|
| 210 |
+
tabNotes.classList.remove('bg-gray-300','dark:bg-gray-700','text-gray-800','dark:text-gray-100');
|
| 211 |
+
tabTasks.classList.add('bg-gray-300','dark:bg-gray-700','text-gray-800','dark:text-gray-100');
|
| 212 |
+
tabTasks.classList.remove('bg-blue-500','text-white');
|
| 213 |
+
loadItems(currentTab);
|
| 214 |
+
});
|
| 215 |
+
|
| 216 |
+
// Load default tab
|
| 217 |
+
loadItems(currentTab);
|
| 218 |
|
| 219 |
+
</script>
|
| 220 |
</body>
|
| 221 |
</html>
|