|
2 | 2 | <html> |
3 | 3 | <head> |
4 | 4 | <title>Coding Hut Website</title> |
5 | | - <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 6 | + <link href="https://fonts.googleapis.com/css?family=Comfortaa" rel="stylesheet" /> |
6 | 7 | <style> |
7 | 8 | body { |
8 | 9 | overflow-x: hidden; |
9 | | - font-family: Sans-Serif; |
| 10 | + font-family: "Comfortaa", Sans-Serif; |
10 | 11 | margin: 0; |
| 12 | + font-size: 22px; |
11 | 13 | } |
12 | | -<link href='https://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet'> |
13 | | -<style> |
14 | | -body { |
15 | | - font-family: 'Comfortaa';font-size: 22px; |
16 | | -} |
17 | 14 |
|
18 | 15 | .menu-container { |
19 | 16 | position: relative; |
|
108 | 105 | <nav class="menu-container"> |
109 | 106 | <!-- Logo --> |
110 | 107 | <a href="https://scratch-coding-hut.github.io" class="menu-logo"> |
111 | | - <img src="Images/Coding-Hut-Logo.png" alt="Coding Hut Logo" width="50" height="50"></img> |
| 108 | + <img src="Images/Coding-Hut-Logo.png" alt="Coding Hut Logo" width="50" height="50" /> |
112 | 109 | </a> |
113 | 110 |
|
114 | 111 | <!-- Menu for Mobile --> |
|
129 | 126 | </div> |
130 | 127 | </nav> |
131 | 128 |
|
132 | | - <h1 id="user" style="text-align:center;"><b>Coding Hut</b></h1> |
133 | | - <h2 style="text-align:center;">Welcome to your dashboard</h2> |
134 | | - <p id="data" style="text-align:center;">COMING SOON</p> |
| 129 | + <h1 id="user" style="text-align: center"><b>Coding Hut</b></h1> |
| 130 | + <h2 style="text-align: center">Welcome to your dashboard</h2> |
| 131 | + <p id="data" style="text-align: center">COMING SOON</p> |
135 | 132 |
|
136 | 133 | <script> |
137 | | - const username = localStorage.getItem('username'); |
138 | | -if (username) { |
139 | | - document.getElementById('user').textContent = username; |
140 | | - |
141 | | - try { |
142 | | - const res = await fetch(`https://scratch-coding-hut-data.onrender.com/${username}`); |
143 | | - const data = await res.json(); |
144 | | - |
145 | | - if (data) { |
146 | | - document.getElementById('data').textContent = JSON.stringify(data); |
| 134 | + // Fetch user data and update UI |
| 135 | + async function loadUserData() { |
| 136 | + const username = localStorage.getItem("username"); |
| 137 | + |
| 138 | + if (username) { |
| 139 | + document.getElementById("user").textContent = username; |
| 140 | + |
| 141 | + try { |
| 142 | + const res = await fetch(`https://scratch-coding-hut-data.onrender.com/${username}`); |
| 143 | + const data = await res.json(); |
| 144 | + |
| 145 | + if (data) { |
| 146 | + document.getElementById("data").textContent = JSON.stringify(data); |
| 147 | + } |
| 148 | + } catch (error) { |
| 149 | + console.error("Error fetching data:", error); |
| 150 | + document.getElementById("data").textContent = "Failed to load data."; |
| 151 | + } |
147 | 152 | } |
148 | | - } catch (error) { |
149 | | - console.error('Error fetching data:', error); |
150 | | - } |
151 | | -} |
152 | | - |
| 153 | + } |
| 154 | + |
| 155 | + // Menu toggle for mobile |
153 | 156 | function toggleMenu() { |
154 | | - var menu = document.querySelector('.menu'); |
155 | | - menu.style.display = menu.style.display === 'flex' ? 'none' : 'flex'; |
| 157 | + var menu = document.querySelector(".menu"); |
| 158 | + menu.style.display = menu.style.display === "flex" ? "none" : "flex"; |
156 | 159 | } |
| 160 | + |
| 161 | + // Load user data on page load |
| 162 | + document.addEventListener("DOMContentLoaded", loadUserData); |
157 | 163 | </script> |
158 | 164 | </body> |
159 | 165 | </html> |
0 commit comments