File size: 16,205 Bytes
7c726af
 
 
 
 
 
 
6267b9c
03cf0e2
7c726af
03cf0e2
 
 
 
 
 
 
 
 
 
7c726af
03cf0e2
 
 
 
dac1051
 
03cf0e2
 
 
7c726af
03cf0e2
 
 
 
 
 
 
 
7c726af
03cf0e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c726af
 
03cf0e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dac1051
 
6267b9c
 
 
 
 
 
03cf0e2
6267b9c
 
 
03cf0e2
6267b9c
03cf0e2
 
6267b9c
 
 
 
dac1051
03cf0e2
6267b9c
 
03cf0e2
 
6267b9c
 
 
7c726af
6267b9c
 
 
 
 
 
 
 
03cf0e2
6267b9c
 
03cf0e2
6267b9c
 
7c726af
6267b9c
 
03cf0e2
7c726af
 
6267b9c
03cf0e2
6267b9c
 
7c726af
6267b9c
 
03cf0e2
7c726af
 
 
6267b9c
03cf0e2
6267b9c
 
03cf0e2
6267b9c
 
 
7c726af
 
 
dac1051
7c726af
6267b9c
 
 
03cf0e2
6267b9c
 
7c726af
6267b9c
 
 
 
03cf0e2
6267b9c
 
 
 
 
 
 
03cf0e2
6267b9c
7c726af
6267b9c
03cf0e2
6267b9c
 
03cf0e2
6267b9c
 
7c726af
6267b9c
 
 
 
7c726af
 
6267b9c
7c726af
6267b9c
03cf0e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6267b9c
 
 
 
 
 
03cf0e2
6267b9c
03cf0e2
 
6267b9c
 
 
03cf0e2
 
 
 
 
 
 
6267b9c
03cf0e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c726af
03cf0e2
 
6267b9c
 
03cf0e2
6267b9c
 
03cf0e2
 
 
 
6267b9c
 
 
 
 
 
03cf0e2
 
 
6267b9c
 
03cf0e2
6267b9c
03cf0e2
6267b9c
 
 
 
 
 
 
 
 
03cf0e2
 
6267b9c
 
 
 
03cf0e2
6267b9c
 
 
 
03cf0e2
 
6267b9c
 
 
 
 
 
 
 
7c726af
03cf0e2
 
7c726af
6267b9c
 
 
 
 
 
 
03cf0e2
 
6267b9c
 
 
 
 
 
03cf0e2
 
6267b9c
 
 
03cf0e2
6267b9c
03cf0e2
6267b9c
03cf0e2
 
 
 
6267b9c
 
 
 
 
 
03cf0e2
 
6267b9c
 
 
 
03cf0e2
 
6267b9c
 
 
03cf0e2
6267b9c
 
 
7c726af
03cf0e2
6267b9c
 
 
 
 
 
 
 
 
 
03cf0e2
6267b9c
 
 
 
 
 
 
 
 
 
03cf0e2
 
6267b9c
 
03cf0e2
 
6267b9c
 
 
 
03cf0e2
6267b9c
 
 
 
 
03cf0e2
6267b9c
 
03cf0e2
6267b9c
 
 
 
 
 
03cf0e2
 
 
 
 
 
 
 
 
7c726af
03cf0e2
7c726af
03cf0e2
7c726af
03cf0e2
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
<!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>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body class="bg-[#F7F8F9] min-h-screen">
   <!-- NAVBAR -->
    <nav
      class="fixed top-0 left-0 w-full z-50 backdrop-blur-md bg-white/20 border-b border-white/30 shadow-md"
    >
      <div class="flex justify-between items-center w-full px-6 py-4">
        <!-- Logo -->
        <a
          href="index.html"
          class="text-2xl font-bold text-black hover:text-[var(--tropical-indigo)] transition"
        >
          CTRL + ALT + HEAL
        </a>

        <ul class="hidden md:flex space-x-6 font-medium text-gray-800">
          <li><a href="index.html" class="nav-link" style="display:none;">Home</a></li>
          <li><a href="profile.html" class="nav-link">Profile</a></li>
          <li><a href="analyzer.html" class="nav-link">Analyzer</a></li>
          <li><a href="past_data.html" class="nav-link">Past Reports</a></li>
          <li id="authNavItem"><a href="login.html" class="nav-link">Login</a></li>
        </ul>

        <!-- Hamburger Menu -->
        <button
          id="hamburger"
          class="md:hidden text-[var(--latte-cream)] text-2xl"
        >
          โ˜ฐ
        </button>
      </div>
<!-- Changes added for change marker for style change-->
      <!-- Mobile Menu -->
      <ul
        id="mobile-menu"
        class="hidden flex-col space-y-4 bg-white/30 backdrop-blur-lg border border-white/20 rounded-xl shadow-lg mt-2 p-4 mx-6 md:hidden"
      >
        <li>
          <a
            href="index.html"
            class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
            >Home</a
          >
        </li>
        <li>
          <a
            href="analyzer.html"
            class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
            >Analyzer</a
          >
        </li>
        <li>
          <a
            href="profile.html"
            class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
            >Profile</a
          >
        </li>
        <li>
          <a
            href="login.html"
            class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
            >Login</a
          >
        </li>
        <li>
          <a
            href="about.html"
            class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
            >About</a
          >
        </li>
  
          >
        </li>
      </ul>
    </nav>

    <script>
      const hamburger = document.getElementById("hamburger");
      const mobileMenu = document.getElementById("mobile-menu");
      hamburger.addEventListener("click", () => {
        mobileMenu.classList.toggle("hidden");
      });
      // Underline the active page only
      const currentPath = window.location.pathname.split("/").pop();
      document.querySelectorAll(".nav-link").forEach((link) => {
        if (link.getAttribute("href") === currentPath) {
          link.classList.add("active-page"); // we'll style this in CSS
        }
      });
      document.querySelectorAll("#mobile-menu a").forEach((link) => {
        if (link.getAttribute("href") === currentPath) {
          link.classList.add("active-page");
        }
      });
    </script>

    <div class="container mx-auto px-6 pt-24">
      <div class="bg-white border border-gray-200 rounded-lg p-6 shadow mb-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 px-4 py-2 rounded">
              Edit Profile
            </button>
            <a href="analyzer.html"
              ><button id="analyzerBtn" class="mt-2 px-4 py-2 rounded">
                Go To Analyzer
              </button></a
            >
          </div>

          <!-- User Info -->
          <div>
            <h2 class="text-xl font-semibold mb-4">Your Profile</h2>
            <p class="mb-2">
              Name: <span id="userName" class="font-medium">Loading...</span>
            </p>
            <p class="mb-2">
              DOB: <span id="userDOB" class="font-medium">Loading...</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">
          <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>
          <div class="flex-1">
            <h1 class="text-3xl font-semibold mb-4">Edit Profile</h1>
            <div class="space-y-4">
              <div>
                <label for="inputName" class="block text-sm font-medium"
                  >Name</label
                >
                <input
                  type="text"
                  id="inputName"
                  class="w-full border 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"
                  >Date of Birth</label
                >
                <input
                  type="date"
                  id="inputDOB"
                  class="w-full border rounded px-3 py-2 focus:ring-2 focus:ring-[#6B9080] focus:outline-none"
                />
              </div>
            </div>
            <div class="flex space-x-2 mt-4">
              <button id="saveProfileBtn" class="px-4 py-2 rounded">
                Save
              </button>
              <button id="cancelProfileBtn" class="px-4 py-2 rounded">
                Cancel
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>

      <!-- Chart Section -->
      <div class="mt-10" id="chartSection">
        <div class="bg-white border border-gray-200 rounded-lg p-6 mb-6">
          <h2 class="text-xl font-semibold mb-4">Health Progress</h2>
          <div
            class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6"
          >
            <div class="flex flex-1 gap-2">
              <input
                type="date"
                id="entryDate"
                class="flex-1 border 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 rounded px-3 py-2 focus:ring-2 focus:ring-[#6B9080] focus:outline-none"
              />
            </div>
            <div class="flex gap-2">
              <button id="addEntryBtn" class="px-4 py-2 rounded">
                Add Entry
              </button>
              <button id="resetChartBtn" class="px-4 py-2 rounded">
                Reset Chart
              </button>
            </div>
          </div>
          <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,
        collection,
        addDoc,
        serverTimestamp,
      } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-firestore.js";
    
      // ๐Ÿ”ฅ Firebase config
      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...",
      };
    
      // ๐Ÿ”ง Init
      const app = initializeApp(firebaseConfig);
      const auth = getAuth(app);
      const db = getFirestore(app);
    
      // Expose Firestore helpers if you need them elsewhere
      window.firebaseAuth = auth;
      window.onAuthStateChanged = onAuthStateChanged;
      window.firestoreDb = db;
      window.firestoreHelpers = { collection, doc, addDoc, serverTimestamp };
    
      let currentUser = null;
    
      // โœ… Auth state check
      // โœ… Hide Home button when logged in
const homeNavDesktop = document.querySelector('ul.md\\:flex li a[href="index.html"]')
  ?.parentElement; // Desktop <li>
const homeNavMobile = document.querySelector('#mobile-menu a[href="index.html"]')
  ?.parentElement; // Mobile <li>

onAuthStateChanged(auth, async (user) => {
  const authNavItem = document.getElementById("authNavItem");

  if (user) {
    currentUser = user;
    await loadUserProfile();

    // Swap login with logout
    if (authNavItem) {
      authNavItem.innerHTML =
        '<button onclick="logout()" class="hover:text-[#6B9080] text-red-600">Logout</button>';
    }

    // Hide Home button
    if (homeNavDesktop) homeNavDesktop.style.display = "none";
    if (homeNavMobile) homeNavMobile.style.display = "none";

  } else {
    if (authNavItem) {
      authNavItem.innerHTML =
        '<a href="login.html" class="hover:text-[#6B9080]">Login</a>';
    }

    // Show Home button again
    if (homeNavDesktop) homeNavDesktop.style.display = "";
    if (homeNavMobile) homeNavMobile.style.display = "";

    window.location.href = "login.html";
  }
});

    
      // ๐Ÿ“„ Load user profile from Firestore
      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);
        }
      }
    
      // ๐Ÿ’พ Save profile to Firestore
      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;
        }
      };
    
      // ๐Ÿšช Logout
      window.logout = async () => {
        try {
          await signOut(auth);
          localStorage.clear();
          window.location.href = "login.html";
        } catch (error) {
          console.error("Error signing out:", error);
        }
      };
    
      // ๐Ÿ“Š LocalStorage for progress data
      function loadProgressData() {
        return JSON.parse(localStorage.getItem("progressData") || "[]");
      }
      function saveProgressData(data) {
        localStorage.setItem("progressData", JSON.stringify(data));
      }
      function resetProgressData() {
        localStorage.removeItem("progressData");
      }
    
      // ๐Ÿ–ผ๏ธ DOM Content Loaded logic
      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");
    
        // Toggle to edit mode
        editBtn.addEventListener("click", () => {
          inputName.value = document.getElementById("userName").textContent;
          inputDOB.value = document.getElementById("userDOB").textContent;
          profileView.classList.add("hidden");
          profileEdit.classList.remove("hidden");
        });
    
        // Save profile
        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.");
          }
        });
    
        // Cancel editing
        cancelBtn.addEventListener("click", () => {
          profileEdit.classList.add("hidden");
          profileView.classList.remove("hidden");
        });
    
        // Chart setup
        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");
        }
    
        const stored = loadProgressData();
        const labels = stored.map((e) => e.date);
        const ctx = document.getElementById("progressChart").getContext("2d");
        const progressChart = new Chart(ctx, {
          type: "line",
          data: {
            labels,
            datasets: [
              {
                label: "Health Score",
                data: stored.map((e) => e.score),
                borderColor: "#6B9080",
                fill: true,
                tension: 0.4,
              },
            ],
          },
          options: {
            scales: { y: { beginAtZero: true, max: 100 } },
          },
        });
    
        // Add Entry
        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 Chart
        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>