Spaces:
Running
Running
File size: 13,685 Bytes
7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c 7c726af 6267b9c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Profile - CTRL + ALT + HEAL</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body class="bg-[#F7F8F9] text-gray-800 min-h-screen">
<!-- Navbar -->
<nav class="bg-white border border-gray-200 px-6 py-4 mb-6">
<div class="container mx-auto flex justify-between items-center">
<a href="index.html" class="text-2xl font-bold text-[#6B9080]"
>CTRL + ALT + HEAL</a
>
<ul class="flex space-x-6 text-sm font-medium text-gray-700">
<li><a href="index.html" class="hover:text-[#6B9080]">Home</a></li>
<li>
<a href="analyzer.html" class="hover:text-[#6B9080]">Analyzer</a>
</li>
<li>
<a href="profile.html" class="hover:text-[#6B9080]">Profile</a>
</li>
<li><button onclick="logout()" class="text-red-500">Logout</button></li>
</ul>
</div>
</nav>
<div class="container mx-auto px-6">
<!-- VIEW MODE -->
<div id="profileViewSection">
<div class="flex items-start space-x-6 mb-10">
<!-- Avatar & Edit Button -->
<div class="flex flex-col items-center">
<div class="w-32 h-32 bg-gray-300 rounded-full"></div>
<button
id="editProfileBtn"
class="mt-2 bg-[#6B9080] text-white px-4 py-2 rounded hover:bg-[#5b7e6a] transition"
>
Edit Profile
</button>
<a href="analyzer.html"
><button
class="mt-2 bg-[#6B9080] text-white px-4 py-2 rounded hover:bg-[#5b7e6a] transition"
>
Go To Analyzer
</button>
</a>
</div>
<!-- User Info -->
<div>
<h1 class="text-3xl font-semibold text-gray-800 mb-4">
Your Profile
</h1>
<p class="text-gray-700 mb-2">
Name: <span id="userName" class="font-medium">Loading...</span>
</p>
<p class="text-gray-700 mb-2">
DOB: <span id="userDOB" class="font-medium">Loding...</span>
</p>
<!-- <p class="text-gray-700 mb-2">
Big Things We Should Fix:
<span id="userFix" class="font-medium"></span>
</p>
<p class="text-gray-700 mb-6">
Health Goals: <span id="userGoals" class="font-medium"></span>
</p> -->
</div>
</div>
</div>
<!-- EDIT MODE -->
<div id="profileEditSection" class="hidden mb-10">
<div class="flex flex-col sm:flex-row items-start space-x-6">
<!-- Avatar Placeholder -->
<div class="flex flex-col items-center mb-4 sm:mb-0">
<div class="w-32 h-32 bg-gray-300 rounded-full"></div>
</div>
<!-- Edit Form -->
<div class="flex-1">
<h1 class="text-3xl font-semibold text-gray-800 mb-4">
Edit Profile
</h1>
<div class="space-y-4">
<div>
<label
for="inputName"
class="block text-sm font-medium text-gray-600"
>Name</label
>
<input
type="text"
id="inputName"
class="w-full border border-gray-300 rounded px-3 py-2 focus:ring-2 focus:ring-[#6B9080] focus:outline-none"
/>
</div>
<div>
<label
for="inputDOB"
class="block text-sm font-medium text-gray-600"
>Date of Birth</label
>
<input
type="date"
id="inputDOB"
class="w-full border border-gray-300 rounded px-3 py-2 focus:ring-2 focus:ring-[#6B9080] focus:outline-none"
/>
</div>
</div>
</div>
<div class="flex space-x-2 mt-4">
<button
id="saveProfileBtn"
class="bg-[#6B9080] text-white px-4 py-2 rounded hover:bg-[#5b7e6a] transition"
>
Save
</button>
<button
id="cancelProfileBtn"
class="bg-gray-300 text-gray-700 px-4 py-2 rounded hover:bg-gray-400 transition"
>
Cancel
</button>
</div>
</div>
</div>
</div>
<!-- Chart Section -->
<div class="mt-10" id="chartSection">
<!-- Card Wrapper -->
<div class="bg-white border border-gray-200 rounded-lg p-6 mb-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">
Health Progress
</h2>
<!-- Controls Row -->
<div
class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6"
>
<!-- Date & Score Inputs -->
<div class="flex flex-1 gap-2">
<input
type="date"
id="entryDate"
class="flex-1 border border-gray-300 rounded px-3 py-2 focus:ring-2 focus:ring-[#6B9080] focus:outline-none"
/>
<input
type="number"
id="entryScore"
min="0"
max="100"
placeholder="Score"
class="w-24 border border-gray-300 rounded px-3 py-2 focus:ring-2 focus:ring-[#6B9080] focus:outline-none"
/>
</div>
<!-- Buttons -->
<div class="flex gap-2">
<button
id="addEntryBtn"
class="bg-[#6B9080] text-white px-4 py-2 rounded hover:bg-[#5b7e6a] transition"
>
Add Entry
</button>
<button
id="resetChartBtn"
class="bg-red-500 text-white px-4 py-2 rounded hover:bg-red-600 transition"
>
Reset Chart
</button>
</div>
</div>
<!-- Chart Canvas -->
<div class="overflow-x-auto">
<canvas id="progressChart" class="w-full h-64"></canvas>
</div>
</div>
</div>
</div>
<script type="module">
import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.22.0/firebase-app.js';
import { getAuth, onAuthStateChanged, signOut } from 'https://www.gstatic.com/firebasejs/9.22.0/firebase-auth.js';
import { getFirestore, doc, getDoc, updateDoc } from 'https://www.gstatic.com/firebasejs/9.22.0/firebase-firestore.js';
const firebaseConfig = {
apiKey: "AIzaSyAPhM_Ee7cLzyKHs5zyFy8g5ZOk9-pubRI",
authDomain: "login-tutorial-7a9e1.firebaseapp.com",
projectId: "login-tutorial-7a9e1",
storageBucket: "login-tutorial-7a9e1.firebasestorage.app",
messagingSenderId: "491093197824",
appId: "1:491093197824:web:9f866..."
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const db = getFirestore(app);
let currentUser = null;
onAuthStateChanged(auth, async (user) => {
if (user) {
currentUser = user;
await loadUserProfile();
} else {
window.location.href = 'login.html';
}
});
async function loadUserProfile() {
try {
const userDoc = await getDoc(doc(db, 'users', currentUser.uid));
if (userDoc.exists()) {
const userData = userDoc.data();
document.getElementById("userName").textContent = userData.name || "Name not set";
document.getElementById("userDOB").textContent = userData.dob || "DOB not set";
localStorage.setItem("userName", userData.name || "");
localStorage.setItem("userDOB", userData.dob || "");
}
} catch (error) {
console.error("Error loading user profile:", error);
}
}
window.saveProfile = async (name, dob) => {
try {
await updateDoc(doc(db, 'users', currentUser.uid), {
name: name,
dob: dob
});
localStorage.setItem("userName", name);
localStorage.setItem("userDOB", dob);
return true;
} catch (error) {
console.error("Error updating profile:", error);
return false;
}
};
window.logout = async () => {
try {
await signOut(auth);
localStorage.clear();
window.location.href = 'login.html';
} catch (error) {
console.error("Error signing out:", error);
}
};
function loadProgressData() {
return JSON.parse(localStorage.getItem("progressData") || "[]");
}
function saveProgressData(data) {
localStorage.setItem("progressData", JSON.stringify(data));
}
function resetProgressData() {
localStorage.removeItem("progressData");
}
document.addEventListener("DOMContentLoaded", () => {
const profileView = document.getElementById("profileViewSection");
const profileEdit = document.getElementById("profileEditSection");
const editBtn = document.getElementById("editProfileBtn");
const saveBtn = document.getElementById("saveProfileBtn");
const cancelBtn = document.getElementById("cancelProfileBtn");
const inputName = document.getElementById("inputName");
const inputDOB = document.getElementById("inputDOB");
// const inputFix = document.getElementById("inputFix");
// const inputGoals = document.getElementById("inputGoals");
editBtn.addEventListener("click", () => {
inputName.value = document.getElementById("userName").textContent;
inputDOB.value = document.getElementById("userDOB").textContent;
profileView.classList.add("hidden");
profileEdit.classList.remove("hidden");
});
saveBtn.addEventListener("click", async () => {
const nameVal = inputName.value.trim();
const dobVal = inputDOB.value;
const success = await window.saveProfile(nameVal, dobVal);
if (success) {
document.getElementById("userName").textContent = nameVal || "Name not set";
document.getElementById("userDOB").textContent = dobVal || "DOB not set";
profileEdit.classList.add("hidden");
profileView.classList.remove("hidden");
} else {
alert("Error saving profile. Please try again.");
}
});
cancelBtn.addEventListener("click", () => {
profileEdit.classList.add("hidden");
profileView.classList.remove("hidden");
});
const chartSection = document.getElementById("chartSection");
const welcomeMessage = document.getElementById("welcomeMessage");
const isNewUser = localStorage.getItem("isNewUser") === "true";
if (isNewUser) {
welcomeMessage.classList.remove("hidden");
chartSection.classList.add("hidden");
}
//chart logic(line graph)
const stored = loadProgressData();
const labels = stored.map((e) => e.date);
const dataPoints = [
{x:50, y:7},
{x:70, y:30},
];
const ctx = document.getElementById("progressChart").getContext("2d");
const progressChart = new Chart(ctx, {
type: "line",
data: {
labels,
datasets: [
{
label: "Health Score",
data: dataPoints,
borderColor: "#6B9080",
fill: true,
tension: 0.4,
},
],
},
options: {
scales: { y: { beginAtZero: true, max: 100 } },
},
});
document.getElementById("addEntryBtn").addEventListener("click", () => {
const date = document.getElementById("entryDate").value;
const score = parseInt(
document.getElementById("entryScore").value,
10
);
if (!date || isNaN(score)) {
alert("Please select a date and enter a valid score.");
return;
}
stored.push({ date, score });
saveProgressData(stored);
progressChart.data.labels.push(date);
progressChart.data.datasets[0].data.push(score);
progressChart.update();
document.getElementById("entryDate").value = "";
document.getElementById("entryScore").value = "";
if (isNewUser) {
localStorage.setItem("isNewUser", "false");
welcomeMessage.classList.add("hidden");
chartSection.classList.remove("hidden");
}
});
// Reset Button
document
.getElementById("resetChartBtn")
.addEventListener("click", () => {
if (!confirm("Are you sure you want to clear all progress data?"))
return;
resetProgressData();
progressChart.data.labels = [];
progressChart.data.datasets[0].data = [];
progressChart.update();
});
});
</script>
</body>
</html> |