-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommunity.html
More file actions
301 lines (282 loc) · 12.3 KB
/
community.html
File metadata and controls
301 lines (282 loc) · 12.3 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="CODEON is a platform for students to learn, code, and compete in coding challenges. Join our community and earn points, badges, and rewards!">
<meta name="keywords" content="Coding, Challenges, Students, Programming, Uganda, CODEON, Leaderboard, Chat, Gamification">
<title>CODEON Chat & Championship</title>
<link rel="icon" href="codeon logo.png">
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-firestore-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-storage-compat.js"></script>
<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.6.0/dist/confetti.browser.min.js"></script>
<style>
:root{
--bg:#11302e; /* darker deep teal */
--card:#ffffff15;
--text:white;
--accent:#00e0c6;
--hover-accent:#00ffc8;
}
.light{
--bg:#f4f6f8;--card:#ffffffdd;--text:#111;--accent:#00695c;--hover-accent:#00e0c6;
}
*{margin:0;padding:0;box-sizing:border-box;font-family:Segoe UI,sans-serif;}
body{background:var(--bg);color:var(--text);transition:0.5s;overflow-x:hidden;position:relative;}
a{text-decoration:none;color:var(--text);}
header{position:sticky;top:0;background:#111;padding:15px;display:flex;align-items:center;justify-content:space-between;z-index:10;}
header img{height:40px;}
header h1{color:white;margin-left:10px;font-size:24px;}
nav a{color:white;text-decoration:none;margin:0 12px;font-weight:bold;}
nav a:hover{color:gold;}
nav .menu-toggle{display:none;cursor:pointer;}
.container{max-width:1200px;margin:20px auto;padding:10px;}
.card{background:rgba(255,255,255,0.08);padding:20px;border-radius:12px;margin-bottom:20px;transition:.3s;}
input,textarea,select{width:100%;padding:10px;margin:8px 0;border-radius:6px;border:none;}
button{padding:10px 15px;border:none;border-radius:6px;background:gold;color:black;font-weight:bold;cursor:pointer;margin:5px 0;}
button:hover{background:#e6c200;}
.chat-window{max-height:400px;overflow-y:auto;background:rgba(0,0,0,0.2);padding:10px;border-radius:8px;}
.message{display:flex;align-items:flex-start;margin:8px 0;}
.message img{width:35px;height:35px;border-radius:50%;margin-right:10px;}
.message-content{background:rgba(255,255,255,0.1);padding:8px 12px;border-radius:8px;max-width:70%;word-wrap:break-word;}
.message-self{flex-direction:row-reverse;}
.message-self .message-content{background:gold;color:black;}
.users-list{background:rgba(0,0,0,0.15);padding:10px;border-radius:8px;max-height:300px;overflow-y:auto;margin-bottom:10px;}
.users-list div{padding:8px;cursor:pointer;border-radius:6px;margin-bottom:4px;}
.users-list div:hover{background:rgba(255,255,255,0.1);}
.progress-container{background:#333;border-radius:10px;height:12px;margin-top:10px;}
.progress-bar{background:gold;height:12px;width:0%;border-radius:10px;transition:.5s;}
.error{color:red;margin-top:5px;}
@media(max-width:768px){nav a{display:none;}nav .menu-toggle{display:block;color:white;font-size:20px;}}
.menu-open nav a{display:block;margin:10px 0;text-align:center;}
</style>
</head>
<body>
<header>
<div style="display:flex;align-items:center;">
<img src="codeon logo.png" alt="CODEON Logo">
<h1>CODEON</h1>
</div>
<nav>
<a href="index.html">Home</a>
<a href="enroll.html">Enroll</a>
<a href="verify.html">Verify</a>
<a href="community-codeon.html">Community</a>
<a href="aboutus.html">About</a>
<span class="menu-toggle">☰</span>
</nav>
</header>
<div class="container" id="authSection">
<div class="card">
<h2>Login / Sign Up</h2>
<input type="text" id="usernameInput" placeholder="Username">
<input type="email" id="emailInput" placeholder="Email">
<input type="password" id="passwordInput" placeholder="Password">
<input type="text" id="schoolInput" placeholder="School">
<select id="countryInput">
<option value="Uganda">Uganda</option>
<option value="Kenya">Kenya</option>
<option value="Nigeria">Nigeria</option>
<option value="Ghana">Ghana</option>
<option value="South Africa">South Africa</option>
</select>
<input type="text" id="photoURLInput" placeholder="Profile Image URL (optional)">
<button onclick="signup()">Sign Up</button>
<button onclick="login()">Login</button>
<p id="authError" class="error"></p>
</div>
</div>
<div class="container" id="main" style="display:none;">
<div class="card">
<h2>Dashboard</h2>
<p id="welcome"></p>
<p>Points: <strong id="points">0</strong> | Level: <strong id="level">1</strong> | Streak: <strong id="streak">0</strong> 🔥</p>
<div class="progress-container"><div id="progressBar" class="progress-bar"></div></div>
<button onclick="claimDailyBonus()">Claim Daily Bonus (+20 XP)</button>
<p id="bonusMsg"></p>
</div>
<div class="card">
<h2>Daily Challenge</h2>
<select id="difficulty">
<option value="Easy">Easy (+50 XP)</option>
<option value="Medium">Medium (+100 XP)</option>
<option value="Hard">Hard (+200 XP)</option>
</select>
<textarea id="challengeCode" placeholder="Write your code here..."></textarea>
<button onclick="submitChallenge()">Submit Challenge</button>
<p id="challengeMsg"></p>
</div>
<div class="card">
<h2>Group Chat</h2>
<div class="chat-window" id="groupChat"></div>
<textarea id="groupMessage" placeholder="Type message or image URL..."></textarea>
<button onclick="sendGroupMessage()">Send</button>
</div>
<div class="card">
<h2>Private Messaging</h2>
<div class="users-list" id="usersList"></div>
<div class="chat-window" id="privateChat"></div>
<textarea id="privateMessage" placeholder="Type message or image URL..."></textarea>
<button onclick="sendPrivateMessage()">Send</button>
</div>
</div>
<script>
// Firebase
const firebaseConfig = {
apiKey:"AIzaSyD_LR9Kllj7hoKTiJAaSxyHglSO6r5gh-g",
authDomain:"codeon-3cb1c.firebaseapp.com",
projectId:"codeon-3cb1c",
storageBucket:"codeon-3cb1c.appspot.com"
};
firebase.initializeApp(firebaseConfig);
const auth=firebase.auth();
const db=firebase.firestore();
const storage=firebase.storage();
let currentUser=null;
let selectedUser=null;
// Responsive nav
document.querySelector('.menu-toggle').addEventListener('click',()=>{document.body.classList.toggle('menu-open');});
// Auth
function signup(){
const email=document.getElementById('emailInput').value;
const password=document.getElementById('passwordInput').value;
const username=document.getElementById('usernameInput').value;
const school=document.getElementById('schoolInput').value;
const country=document.getElementById('countryInput').value;
const photo=document.getElementById('photoURLInput').value;
if(!email||!password||!username||!school){document.getElementById('authError').innerText="All fields required";return;}
auth.createUserWithEmailAndPassword(email,password)
.then(u=>{
return db.collection("users").doc(u.user.uid).set({
email,email,name:username,school,country,points:0,level:1,streak:0,photoURL:photo||'https://i.pravatar.cc/150'
});
}).catch(e=>document.getElementById('authError').innerText=e.message);
}
function login(){
const email=document.getElementById('emailInput').value;
const password=document.getElementById('passwordInput').value;
auth.signInWithEmailAndPassword(email,password).catch(e=>document.getElementById('authError').innerText=e.message);
}
function logout(){auth.signOut();}
// Dashboard
auth.onAuthStateChanged(user=>{
if(user){
currentUser=user;
document.getElementById('authSection').style.display="none";
document.getElementById('main').style.display="block";
loadUser();
loadUsersList();
loadGroupChat();
} else {
document.getElementById('authSection').style.display="block";
document.getElementById('main').style.display="none";
}
});
function loadUser(){
db.collection("users").doc(currentUser.uid).onSnapshot(doc=>{
const d=doc.data();
document.getElementById('welcome').innerText="Welcome "+d.name;
document.getElementById('points').innerText=d.points;
document.getElementById('level').innerText=d.level;
document.getElementById('streak').innerText=d.streak;
const percent=((d.points||0)%200)/200*100;
document.getElementById('progressBar').style.width=percent+"%";
});
}
function claimDailyBonus(){
const ref=db.collection("users").doc(currentUser.uid);
ref.get().then(doc=>{
const today=new Date().toDateString();
if(doc.data().lastBonus===today){document.getElementById('bonusMsg').innerText="Already claimed today"; return;}
ref.update({points:(doc.data().points||0)+20,lastBonus:today});
document.getElementById('bonusMsg').innerText="🔥 +20 XP!";
confetti({particleCount:40,spread:70,origin:{y:0.6}});
});
}
function getXP(diff){if(diff==="Easy")return 50;if(diff==="Medium")return 100;if(diff==="Hard")return 200;return 50;}
function submitChallenge(){
const xp=getXP(document.getElementById('difficulty').value);
const ref=db.collection("users").doc(currentUser.uid);
const today=new Date().toDateString();
ref.get().then(doc=>{
if(doc.data().lastSubmit===today){document.getElementById('challengeMsg').innerText="Already submitted today!"; return;}
ref.update({points:(doc.data().points||0)+xp,lastSubmit:today});
document.getElementById('challengeMsg').innerText="✅ +"+xp+" XP!";
confetti({particleCount:30,spread:70,origin:{y:0.6}});
});
}
// Users list
function loadUsersList(){
db.collection("users").onSnapshot(snap=>{
const list=document.getElementById('usersList'); list.innerHTML='';
snap.forEach(doc=>{
const d=doc.data();
if(doc.id!==currentUser.uid){
const div=document.createElement('div');
div.innerText=d.name;
div.onclick=()=>{selectedUser=doc.id;document.getElementById('privateChat').innerHTML='';loadPrivateChat();};
list.appendChild(div);
}
});
});
}
// Group chat
function loadGroupChat(){
db.collection("groupMessages").orderBy("timestamp").onSnapshot(snap=>{
const chat=document.getElementById('groupChat'); chat.innerHTML='';
snap.forEach(doc=>{
const m=doc.data();
const div=document.createElement('div'); div.className='message'+(m.sender===currentUser.uid?' message-self':'');
div.innerHTML=`<img src="${m.photo}" alt="profile"><div class="message-content"><b>${m.name}</b>: ${m.text.startsWith('http')?'<img src="'+m.text+'" style="max-width:150px;">':m.text}</div>`;
chat.appendChild(div);
chat.scrollTop=chat.scrollHeight;
});
});
}
function sendGroupMessage(){
const txt=document.getElementById('groupMessage').value.trim();
if(!txt)return;
db.collection("users").doc(currentUser.uid).get().then(doc=>{
const d=doc.data();
db.collection("groupMessages").add({sender:currentUser.uid,name:d.name,photo:d.photoURL,text:txt,timestamp:firebase.firestore.FieldValue.serverTimestamp()});
document.getElementById('groupMessage').value='';
confetti({particleCount:20,spread:70,origin:{y:0.6}});
});
}
// Private chat
function loadPrivateChat(){
if(!selectedUser)return;
db.collection("privateMessages").where('participants','array-contains',currentUser.uid).orderBy('timestamp')
.onSnapshot(snap=>{
const chat=document.getElementById('privateChat'); chat.innerHTML='';
snap.forEach(doc=>{
const m=doc.data();
if(m.participants.includes(selectedUser)){
const div=document.createElement('div'); div.className='message'+(m.sender===currentUser.uid?' message-self':'');
div.innerHTML=`<img src="${m.photo}" alt="profile"><div class="message-content"><b>${m.name}</b>: ${m.text.startsWith('http')?'<img src="'+m.text+'" style="max-width:150px;">':m.text}</div>`;
chat.appendChild(div);
chat.scrollTop=chat.scrollHeight;
}
});
});
}
function sendPrivateMessage(){
if(!selectedUser)return alert('Select a user first');
const txt=document.getElementById('privateMessage').value.trim(); if(!txt)return;
db.collection("users").doc(currentUser.uid).get().then(doc=>{
const d=doc.data();
db.collection("privateMessages").add({
sender:currentUser.uid,name:d.name,photo:d.photoURL,
participants:[currentUser.uid,selectedUser],
text:txt,
timestamp:firebase.firestore.FieldValue.serverTimestamp()
});
document.getElementById('privateMessage').value='';
confetti({particleCount:15,spread:70,origin:{y:0.6}});
});
}
</script>
</body>
</html>