-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraise.html
More file actions
423 lines (383 loc) · 18.6 KB
/
Copy pathraise.html
File metadata and controls
423 lines (383 loc) · 18.6 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Raise Community</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
body {
background-color: #0a0a0a;
color: #e0e0e0;
font-family: 'Inter', sans-serif;
}
.member-badge {
padding: 2px 6px;
border-radius: 4px;
font-size: 0.8rem;
font-weight: bold;
}
.owner-badge { background-color: #9333ea; color: white; }
.admin-badge { background-color: #ef4444; color: white; }
.member-badge-yellow { background-color: #facc15; color: black; }
.modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
display: flex;
justify-content: center;
align-items: center;
z-index: 50;
}
</style>
</head>
<body class="min-h-screen flex justify-center items-start">
<div class="relative w-full max-w-xl mx-auto rounded-3xl overflow-hidden shadow-2xl pb-20">
<!-- Community Header -->
<div class="relative">
<div class="h-64 rounded-b-3xl bg-cover bg-center" style="background-image: url('https://placehold.co/1200x600/1C2833/ffffff?text=Raise');">
<div class="absolute inset-0 bg-black opacity-50 rounded-b-3xl"></div>
<div class="relative p-6 flex items-center justify-between z-10">
<button onclick="window.history.back()" class="text-white text-3xl font-bold rounded-full p-2 bg-gray-800 bg-opacity-50">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
</svg>
</button>
<div class="flex items-center space-x-2">
<button class="text-white text-xl rounded-full p-2 bg-gray-800 bg-opacity-50">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9" />
</svg>
</button>
</div>
</div>
<div class="absolute bottom-6 left-6 text-white text-shadow-lg z-10">
<p id="member-count" class="text-lg font-semibold flex items-center space-x-2">
<span class="text-green-400">Loading...</span>
</p>
<h1 class="text-5xl font-extrabold mt-1">Raise Community</h1>
</div>
</div>
</div>
<!-- Tabs -->
<div class="flex bg-gray-900 rounded-t-3xl pt-2 pb-2 -mt-4 z-20 relative shadow-inner">
<button onclick="showTab('posts')" id="posts-tab" class="flex-1 text-center py-3 text-lg font-semibold transition-all duration-300 text-white border-b-2 border-purple-500">
Posts
</button>
<button onclick="showTab('members')" id="members-tab" class="flex-1 text-center py-3 text-lg font-semibold transition-all duration-300 text-gray-400">
Members
</button>
</div>
<!-- Main Content -->
<div class="container mx-auto mt-4 px-4 pb-20">
<!-- Posts Feed -->
<div id="posts-feed" class="space-y-4"></div>
<!-- Members List -->
<div id="members-list" class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-4 hidden"></div>
</div>
</div>
<!-- Floating Action Button -->
<button id="create-post-btn" onclick="openCreateModal('post')" class="fixed bottom-24 right-6 bg-purple-600 text-white rounded-full p-4 shadow-lg hover:bg-purple-700 transition-colors duration-300 transform scale-100 hover:scale-110 z-30 hidden">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4v16m8-8H4" />
</svg>
</button>
<!-- Bottom Navigation Bar -->
<div class="fixed bottom-0 w-full max-w-xl bg-gray-900 border-t border-gray-700 py-3 px-4 flex justify-around items-center rounded-t-3xl shadow-lg z-30">
<a href="homepage.html" class="flex flex-col items-center text-xs text-purple-500">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" viewBox="0 0 20 20" fill="currentColor">
<path d="M10.707 2.293a1 1 0 00-1.414 0l-7 7a1 1 0 001.414 1.414L4 10.414V17a1 1 0 001 1h2a1 1 0 001-1v-2a1 1 0 011-1h2a1 1 0 011 1v2a1 1 0 001 1h2a1 1 0 001-1v-6.586l.293.293a1 1 0 001.414-1.414l-7-7z" />
</svg>
Home
</a>
<a href="#" class="flex flex-col items-center text-xs text-gray-400">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z" />
</svg>
DM
</a>
<a href="#" class="flex flex-col items-center text-xs text-gray-400">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37a1.724 1.724 0 002.572-1.065z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
</svg>
Settings
</a>
</div>
<!-- Modals for Post and Poll Creation -->
<div id="create-modal-post" class="modal hidden">
<div class="bg-gray-800 p-6 rounded-xl shadow-lg w-11/12 max-w-sm">
<h2 class="text-xl font-bold mb-4">Create New Post</h2>
<textarea id="post-content" class="w-full p-2 bg-gray-700 rounded-lg text-white mb-4" rows="4" placeholder="What's on your mind?"></textarea>
<div class="flex justify-end space-x-2">
<button onclick="closeCreateModal('post')" class="px-4 py-2 text-gray-400 rounded-lg hover:text-white">Cancel</button>
<button onclick="createPost()" class="px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700">Post</button>
</div>
</div>
</div>
<div id="create-modal-poll" class="modal hidden">
<div class="bg-gray-800 p-6 rounded-xl shadow-lg w-11/12 max-w-sm">
<h2 class="text-xl font-bold mb-4">Create New Poll</h2>
<input type="text" id="poll-question" class="w-full p-2 bg-gray-700 rounded-lg text-white mb-2" placeholder="Poll Question" />
<input type="text" id="poll-options" class="w-full p-2 bg-gray-700 rounded-lg text-white" placeholder="Option 1, Option 2, ..." />
<p class="text-xs text-gray-400 mt-1">Separate options with commas.</p>
<div class="flex justify-end space-x-2 mt-4">
<button onclick="closeCreateModal('poll')" class="px-4 py-2 text-gray-400 rounded-lg hover:text-white">Cancel</button>
<button onclick="createPoll()" class="px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700">Create</button>
</div>
</div>
</div>
<script>
const username = localStorage.getItem('username');
const communityName = 'Raise';
const postsFeed = document.getElementById('posts-feed');
const membersList = document.getElementById('members-list');
const memberCountEl = document.getElementById('member-count');
const postsTab = document.getElementById('posts-tab');
const membersTab = document.getElementById('members-tab');
const createPostBtn = document.getElementById('create-post-btn');
let currentUserRole = 'member'; // Default to member
if(!username) window.location.href='index.html';
async function fetchUserRole() {
try {
const res = await fetch(`/api/community/${communityName}/role`);
if (res.ok) {
const data = await res.json();
currentUserRole = data.role;
if (currentUserRole === 'owner' || currentUserRole === 'admin') {
createPostBtn.classList.remove('hidden');
}
}
} catch (error) {
console.error("Error fetching user role:", error);
}
}
async function fetchCommunityData() {
await fetchUserRole();
try {
// Fetch members
const membersRes = await fetch(`/api/community/${communityName}/members`);
const members = await membersRes.json();
renderMembers(members);
memberCountEl.innerHTML = `<span>${members.length} Members</span> <span class="text-green-400"><svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" /></svg></span> <span class="text-gray-300">Joined</span>`;
// Fetch posts and comments
const postsRes = await fetch(`/api/community/${communityName}/posts`);
const posts = await postsRes.json();
renderPosts(posts);
// Fetch polls
const pollsRes = await fetch(`/api/community/${communityName}/polls`);
const polls = await pollsRes.json();
renderPolls(polls);
} catch (error) {
console.error("Error fetching community data:", error);
memberCountEl.innerHTML = `<span>Error loading data</span>`;
postsFeed.innerHTML = '<p class="text-center text-red-400">Failed to load posts.</p>';
membersList.innerHTML = '<p class="text-center text-red-400">Failed to load members.</p>';
}
}
function renderPosts(posts) {
postsFeed.innerHTML = '';
posts.forEach(p => {
const postElement = document.createElement('div');
postElement.className = "bg-gray-800 rounded-2xl p-4 flex space-x-4 shadow-lg";
const profilePic = `https://placehold.co/100x100/A0B2C3/ffffff?text=${p.author ? p.author[0].toUpperCase() : 'U'}`;
const likesCount = p.likes ? p.likes.length : 0;
let commentsHtml = p.comments.map(c => `
<div class="flex items-center space-x-2 mt-2">
<span class="text-xs font-semibold">${c.author}:</span>
<span class="text-xs text-gray-300">${c.comment}</span>
</div>
`).join('');
postElement.innerHTML = `
<div class="w-12 h-12 flex-shrink-0 cursor-pointer" onclick="navigateToProfile('${p.author}')">
<img src="${profilePic}" alt="Profile" class="w-full h-full rounded-full border-2 border-purple-500"/>
</div>
<div class="flex-1">
<div class="flex items-center justify-between">
<h3 class="text-purple-400 font-bold">${p.author}</h3>
<span class="text-xs text-gray-500">${new Date(p.timestamp).toLocaleString()}</span>
</div>
<p class="text-gray-300 mt-2">${p.content}</p>
<div class="flex items-center space-x-4 mt-4 text-sm text-gray-400">
<button onclick="likePost(${p.id})">
<i class="fas fa-heart text-red-500"></i> ${likesCount}
</button>
<button onclick="openCommentModal(${p.id})">
<i class="fas fa-comment"></i> Comment
</button>
</div>
<div id="comments-section-${p.id}" class="mt-4 border-t border-gray-700 pt-4">
${commentsHtml}
</div>
</div>
`;
postsFeed.appendChild(postElement);
});
}
function renderPolls(polls) {
const pollsFeed = document.createElement('div');
pollsFeed.id = 'polls-feed';
polls.forEach(p => {
const pollElement = document.createElement('div');
pollElement.className = "bg-gray-800 p-4 rounded-lg mb-4";
let optionsHTML = '';
p.options.forEach((o, j) => {
const totalVotes = p.votes.reduce((a, b) => parseInt(a) + parseInt(b), 0);
const percentage = totalVotes > 0 ? (p.votes[j] / totalVotes * 100).toFixed(0) : 0;
optionsHTML += `
<div class="relative w-full mb-2">
<button onclick="votePoll(${p.id}, ${j})" class="w-full text-left bg-gray-700 hover:bg-gray-600 px-4 py-2 rounded-lg transition-colors">
${o} (${p.votes[j]})
</button>
<div class="absolute inset-y-0 left-0 bg-purple-600 opacity-50 rounded-lg" style="width: ${percentage}%"></div>
</div>
`;
});
pollElement.innerHTML = `
<div class="font-bold mb-2">${p.question}</div>
${optionsHTML}
`;
postsFeed.appendChild(pollElement);
});
}
function renderMembers(members) {
membersList.innerHTML = '';
members.forEach(m => {
const memberElement = document.createElement('div');
memberElement.className = "flex flex-col items-center p-3 bg-gray-800 rounded-xl shadow-lg cursor-pointer transition-transform transform hover:scale-105";
memberElement.onclick = () => navigateToProfile(m.username);
const profilePic = m.profile_pic || `https://placehold.co/100x100/A0B2C3/ffffff?text=${m.username ? m.username[0].toUpperCase() : 'U'}`;
let roleBadgeClass = '';
if (m.role === 'owner') roleBadgeClass = 'owner-badge';
else if (m.role === 'admin') roleBadgeClass = 'admin-badge';
else roleBadgeClass = 'member-badge-yellow';
memberElement.innerHTML = `
<img src="${profilePic}" alt="Member profile" class="w-16 h-16 rounded-full border-2 border-purple-500" />
<p class="mt-2 text-sm font-medium text-white truncate w-full text-center">${m.username}</p>
<span class="member-badge ${roleBadgeClass}">${m.role.toUpperCase()}</span>
`;
if (currentUserRole === 'owner' && m.role === 'member') {
const assignBtn = document.createElement('button');
assignBtn.className = "mt-2 px-2 py-1 bg-red-500 text-white text-xs rounded-lg hover:bg-red-600";
assignBtn.textContent = "Assign Admin";
assignBtn.onclick = (e) => {
e.stopPropagation(); // Prevent navigating to profile
assignAdminRole(m.username);
};
memberElement.appendChild(assignBtn);
}
membersList.appendChild(memberElement);
});
}
function showTab(tabName) {
postsFeed.classList.add('hidden');
membersList.classList.add('hidden');
postsTab.classList.remove('text-white', 'border-b-2', 'border-purple-500');
postsTab.classList.add('text-gray-400');
membersTab.classList.remove('text-white', 'border-b-2', 'border-purple-500');
membersTab.classList.add('text-gray-400');
if (tabName === 'posts') {
postsFeed.classList.remove('hidden');
postsTab.classList.add('text-white', 'border-b-2', 'border-purple-500');
postsTab.classList.remove('text-gray-400');
} else if (tabName === 'members') {
membersList.classList.remove('hidden');
membersTab.classList.add('text-white', 'border-b-2', 'border-purple-500');
membersTab.classList.remove('text-gray-400');
}
}
function openCreateModal(type) {
if (type === 'post') {
document.getElementById('create-modal-post').classList.remove('hidden');
} else if (type === 'poll') {
document.getElementById('create-modal-poll').classList.remove('hidden');
}
}
function closeCreateModal(type) {
if (type === 'post') {
document.getElementById('create-modal-post').classList.add('hidden');
} else if (type === 'poll') {
document.getElementById('create-modal-poll').classList.add('hidden');
}
}
async function createPost() {
const content = document.getElementById('post-content').value;
if (!content) return;
const res = await fetch(`/api/community/${communityName}/post`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({ content })
});
if (res.ok) {
closeCreateModal('post');
fetchCommunityData();
} else {
console.error("Failed to create post:", await res.text());
}
}
async function createPoll() {
const question = document.getElementById('poll-question').value;
const options = document.getElementById('poll-options').value;
if (!question || !options) return;
const res = await fetch(`/api/community/${communityName}/poll`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({ question, options })
});
if (res.ok) {
closeCreateModal('poll');
fetchCommunityData();
} else {
console.error("Failed to create poll:", await res.text());
}
}
async function likePost(postId) {
if (currentUserRole === 'guest') {
console.log("You must be a member to like posts.");
return;
}
const res = await fetch(`/api/community/${communityName}/post/${postId}/like`, { method: 'POST' });
if (res.ok) {
fetchCommunityData();
} else {
console.error("Failed to like post:", await res.text());
}
}
async function votePoll(pollId, optionIndex) {
if (currentUserRole === 'guest') {
console.log("You must be a member to vote on polls.");
return;
}
const res = await fetch(`/api/community/${communityName}/poll/${pollId}/vote`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({ optionIndex })
});
if (res.ok) {
fetchCommunityData();
} else {
console.error("Failed to vote:", await res.text());
}
}
async function assignAdminRole(memberUsername) {
const res = await fetch(`/api/community/${communityName}/member/${memberUsername}/assign-admin`, { method: 'POST' });
if (res.ok) {
console.log(`${memberUsername} is now an admin.`);
fetchCommunityData();
} else {
console.error("Failed to assign admin role:", await res.text());
}
}
function navigateToProfile(username) {
console.log(`Navigating to the profile of user: ${username}`);
// Implement your navigation logic here
}
// Initial data fetch and render
fetchCommunityData();
</script>
</body>
</html>