-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
187 lines (163 loc) · 6.7 KB
/
index.html
File metadata and controls
187 lines (163 loc) · 6.7 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>CodeSnap</title>
<link rel="stylesheet" href="static/main.css" />
<link rel="stylesheet" href="static/home.css" />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet">
</head>
<body>
<header class="navbar">
<div class="logo">
<img src="https://codesnap-org.github.io/gui/static/assets/018f79360b10f9f2c317d648d61a0eb2.svg" alt="CodeSnap Logo" />
<span>CodeSnap</span>
</div>
<nav class="nav">
<a href="/projects/editor">Create</a>
<a href="/about">About</a>
<a href="/blog">Blog</a>
<a href="#" id="signupBtn">Sign Up</a>
<a href="#" id="loginBtn">Login</a>
</nav>
</header>
<center>
<main>
<section class="section">
<h2>Featured Projects</h2>
<div class="projects" id="projectsContainer"></div>
</section>
<section class="leaderboard-section">
<h2>Leaderboard</h2>
<div class="leaderboard" id="leaderboardContainer"></div>
</section>
</main>
<!-- Login Modal -->
<div class="modal hidden" id="loginModal">
<div class="modal-content">
<h2>Login</h2>
<form id="loginForm">
<input type="text" name="signupUsername" placeholder="Username" required />
<input type="email" name="loginEmail" placeholder="Email" required />
<input type="password" name="loginPassword" placeholder="Password" required />
<button type="submit">Log In</button>
</form>
<button class="close-modal" data-target="loginModal">Close</button>
</div>
</div>
<!-- Signup Modal -->
<div class="modal hidden" id="signupModal">
<div class="modal-content">
<h2>Sign Up</h2>
<form id="signupForm">
<input type="text" name="signupUsername" placeholder="Username" required />
<input type="email" name="signupEmail" placeholder="Email" required />
<input type="password" name="signupPassword" placeholder="Password" required />
<button type="submit">Sign Up</button>
</form>
<button class="close-modal" data-target="signupModal">Close</button>
</div>
</div>
</center>
<script>
const loginBtn = document.getElementById('loginBtn');
const signupBtn = document.getElementById('signupBtn');
const closeModalBtns = document.querySelectorAll('.close-modal');
loginBtn.addEventListener('click', () => document.getElementById('loginModal').classList.remove('hidden'));
signupBtn.addEventListener('click', () => document.getElementById('signupModal').classList.remove('hidden'));
closeModalBtns.forEach(btn => {
btn.addEventListener('click', () => document.getElementById(btn.dataset.target).classList.add('hidden'));
});
const loginForm = document.getElementById('loginForm');
const signupForm = document.getElementById('signupForm');
const projectsContainer = document.getElementById('projectsContainer');
const leaderboardContainer = document.getElementById('leaderboardContainer');
loginForm.addEventListener('submit', async e => {
e.preventDefault();
const email = e.target.loginEmail.value;
const password = e.target.loginPassword.value;
const res = await fetch('https://block-compiler-codesnap.onrender.com/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': 'test123' },
body: JSON.stringify({ email, password })
});
const data = await res.json();
if (data.message === 'Logged In') {
document.getElementById('loginModal').classList.add('hidden');
alert(`Welcome ${email}`);
} else {
alert('Invalid credentials');
}
});
signupForm.addEventListener('submit', async e => {
e.preventDefault();
const username = e.target.signupUsername.value;
localStorage.setItem('username', username);
const email = e.target.signupEmail.value;
const password = e.target.signupPassword.value;
const img = 'https://u.cubeupload.com/UploadMaster/1000003131.png';
const res = await fetch('https://block-compiler-codesnap.onrender.com/api/join', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': 'test123' },
body: JSON.stringify({ username, email, password, img })
});
const data = await res.json();
if (data.message.includes('success')) {
alert('Sign up successful. You can log in now.');
document.getElementById('signupModal').classList.add('hidden');
} else {
alert('Sign up failed.');
}
});
window.onload = async () => {
try {
const params = new URLSearchParams(window.location.search);
const code = params.get('privateCode');
if (code) {
const res = await fetch(`https://auth-api.itinerary.eu.org/auth/verifyToken/${code}`);
const data = await res.json();
if (data.username) alert(`Welcome back, ${data.username}!`);
}
// Fetch and display projects
const projRes = await fetch('https://corsproxy.io/?url=https://block-compiler-codesnap.onrender.com/api/projects');
const projData = await projRes.json();
if (projRes.status_code == 404) {
alert('Error!');
}
projData.projects.forEach(p => {
const div = document.createElement('a');
div.className = 'project';
// Extract number from original p.link
const match = p.link.match(/\d+/);
const number = match ? match[0] : '0';
// Set the new formatted link
p.link = `https://codesnap-org.github.io/projects/#${number}`;
div.href = p.link;
// Fallback image logic
const image = p.image === 'https://codesnap-org.github.io/projects/static/assets/018f79360b10f9f2c317d648d61a0eb2.svg'
? 'https://codesnap-org.github.io/gui/static/assets/018f79360b10f9f2c317d648d61a0eb2.svg'
: p.image;
div.innerHTML = `
<img src="${image}" alt="${p.name}" />
<h3>${p.name}</h3>
<p>Genre: ${p.genre}</p>
`;
projectsContainer.appendChild(div);
});
// Fetch and display leaderboard
const leadRes = await fetch('https://block-compiler-codesnap.onrender.com/api/leaderboard');
const leadData = await leadRes.json();
leadData.slice(0, 3).forEach((user, i) => {
const div = document.createElement('div');
div.className = 'leader';
div.innerHTML = `<img src="${user.avatar}" alt="${user.name}" /><span>${i + 1}</span>`;
leaderboardContainer.appendChild(div);
});
} catch (err) {
console.error("Error loading content:", err);
}
};
</script>
</body>
</html>