-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
713 lines (609 loc) · 18.5 KB
/
index.html
File metadata and controls
713 lines (609 loc) · 18.5 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
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Feed Page - Postagram</title>
<!-- BOOTSTRAP CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- FontAwesome Icon CDN -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
<!-- ANIMATE.CSS CDN -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
<!-- AOS CSS -->
<link href="https://unpkg.com/aos@2.3.4/dist/aos.css" rel="stylesheet">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "Poppins", sans-serif;
background-color: #f8f9fa;
min-height: 100vh;
}
/* Navbar Styles */
.navbar {
background-color: #ffffff;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
padding: 1rem 0;
}
.navbar-brand {
display: flex;
align-items: center;
gap: 10px;
font-weight: 700;
font-size: 1.25rem;
color: #1e293b;
}
.nav-link {
color: #64748b;
font-weight: 500;
padding: 8px 16px;
border-radius: 8px;
transition: all 0.3s ease;
margin: 0 5px;
}
.nav-link:hover {
background-color: #f1f5f9;
color: #1e293b;
}
.nav-link.active {
background-color: #1e293b;
color: white;
}
/* Ensure buttons look good on all screen sizes */
.nav-links a {
padding: 8px 16px;
margin: 5px;
font-weight: 500;
}
/* Optionally, reduce button size on small screens if needed */
@media (max-width: 576px) {
.nav-links a {
font-size: 0.9rem;
/* Adjust size for small screens */
}
}
.user-info {
display: flex;
align-items: center;
gap: 15px;
}
.user-email {
color: #64748b;
font-size: 0.9rem;
font-weight: 500;
}
.user-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
background: linear-gradient(135deg, #d946ef 0%, #a855f7 100%);
color: white;
font-weight: 600;
font-size: 1rem;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
position: relative;
overflow: hidden;
}
.user-avatar img {
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
display: none;
}
.user-avatar:hover {
transform: scale(1.1);
}
/* Hero Section */
.hero-section {
padding: 2.5rem 0 1.5rem;
}
.welcome-text h1 {
font-size: 2rem;
font-weight: 700;
color: #1e293b;
margin-bottom: 0.5rem;
}
.welcome-text p {
color: #64748b;
font-size: 1rem;
}
/* Category Filter UI */
.filter-box {
display: flex;
align-items: center;
gap: 10px;
background: #ffffff;
padding: 12px 16px;
border-radius: 12px;
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
max-width: 260px;
margin-left: auto;
}
.filter-box i {
color: #d97706;
font-size: 1.1rem;
}
#categoryFilter {
border: none;
font-weight: 500;
cursor: pointer;
}
#categoryFilter:focus {
box-shadow: none;
}
/* Category badge on card */
.category-badge {
background: linear-gradient(135deg, #d946ef 0%, #a855f7 100%);
color: #fff;
font-size: 0.7rem;
font-weight: 600;
padding: 4px 10px;
border-radius: 20px;
white-space: nowrap;
}
/* Posts Grid */
.posts-container {
padding: 2rem 0;
}
.post-card {
background: white;
border-radius: 16px;
overflow: hidden;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
transition: all 0.3s ease;
height: 100%;
display: flex;
flex-direction: column;
}
.post-card:hover {
transform: translateY(-5px);
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
}
.post-image {
width: 100%;
height: 220px;
object-fit: cover;
}
.post-content {
padding: 1.5rem;
flex: 1;
display: flex;
flex-direction: column;
}
.post-title {
font-size: 1.15rem;
font-weight: 700;
color: #1e293b;
margin-bottom: 0.5rem;
line-height: 1.4;
}
.post-meta {
display: flex;
align-items: center;
gap: 5px;
color: #94a3b8;
font-size: 0.85rem;
margin-bottom: 1rem;
}
.post-meta span {
display: flex;
align-items: center;
gap: 3px;
}
.post-description {
color: #64748b;
font-size: 0.95rem;
line-height: 1.6;
margin-top: auto;
}
/* Create Post Modal */
.modal-content {
border-radius: 16px;
border: none;
}
.modal-header {
background: linear-gradient(135deg, #1e293b 0%, #d97706 100%);
color: white;
border-radius: 16px 16px 0 0;
padding: 1.5rem;
}
.modal-title {
font-weight: 700;
font-size: 1.5rem;
}
.btn-close {
filter: brightness(0) invert(1);
}
.form-label {
font-weight: 600;
color: #1e293b;
margin-bottom: 0.5rem;
}
.form-control,
.form-select {
border-radius: 10px;
border: 2px solid #e2e8f0;
padding: 12px 16px;
transition: all 0.3s ease;
}
.form-control:focus,
.form-select:focus {
border-color: #d97706;
box-shadow: 0 0 0 0.25rem rgba(217, 119, 6, 0.1);
}
.btn-submit-post {
background: linear-gradient(135deg, #1e293b 0%, #d97706 100%);
color: white;
border: none;
padding: 12px 32px;
border-radius: 10px;
font-weight: 600;
transition: all 0.3s ease;
}
.btn-submit-post:hover {
background: linear-gradient(135deg, #0f172a 0%, #b45309 100%);
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(217, 119, 6, 0.3);
}
/* Responsive */
@media (max-width: 768px) {
.hero-section {
text-align: center;
}
.welcome-text h1 {
font-size: 1.5rem;
}
.user-email {
display: none;
}
.btn-create-post {
width: 100%;
justify-content: center;
}
}
/* FEED POST AUTHOR AVATAR */
.post-author {
display: flex;
align-items: center;
gap: 8px;
font-weight: 600;
color: #111;
}
.post-avatar {
width: 28px;
height: 28px;
border-radius: 50%;
background: linear-gradient(135deg, #6366f1, #a855f7);
color: #fff;
font-size: 0.75rem;
font-weight: 700;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.post-avatar img {
width: 100%;
height: 100%;
object-fit: cover;
}
</style>
</head>
<body>
<!-- NAVBAR -->
<nav class="navbar navbar-expand-lg">
<div class="container">
<a class="navbar-brand" href="#">
<div class="brand-icon">
<img src="img/logo.png" alt="logo">
</div>
Postagram
</a>
<div class="nav-links mx-auto d-flex flex-wrap justify-content-center">
<a class="nav-link active" href="index.html">
<i class="fas fa-home me-1"></i> Feed
</a>
<a class="nav-link" href="user.html">
<i class="fas fa-folder me-1"></i> My Posts
</a>
</div>
<div class="user-info ms-auto">
<span class="user-email d-none d-md-inline" id="navbarEmail">Loading...</span>
<div class="dropdown">
<div class="user-avatar dropdown-toggle" id="userAvatar" data-bs-toggle="dropdown" aria-expanded="false">
<span id="avatarInitials">?</span>
<img id="avatarImage" src="" alt="avatar">
</div>
<ul class="dropdown-menu dropdown-menu-end">
<li>
<a class="dropdown-item" href="user.html">
<i class="fas fa-user me-2"></i> Profile
</a>
</li>
<li>
<hr class="dropdown-divider">
</li>
<li>
<a class="dropdown-item text-danger" href="#" id="logoutBtn">
<i class="fas fa-sign-out-alt me-2"></i> Logout
</a>
</li>
</ul>
</div>
</div>
</div>
</nav>
<!-- Hero Section -->
<section class="hero-section">
<div class="container">
<div class="row align-items-center g-3">
<div class="col-lg-8 col-md-7">
<div class="welcome-text animate__animated animate__fadeInLeft">
<h1>Grab Your Coffee & Explore the Feed</h1>
<p>Browse community posts by category</p>
</div>
</div>
<div class="col-lg-4 col-md-5 text-md-end">
<div class="filter-box">
<i class="fas fa-filter"></i>
<select id="categoryFilter" class="form-select">
<option value="all">All Categories</option>
<option value="Technology">Technology</option>
<option value="Programming">Programming</option>
<option value="Design">Design</option>
<option value="Photography">Photography</option>
<option value="Lifestyle">Lifestyle</option>
<option value="Travel">Travel</option>
</select>
</div>
</div>
</div>
</div>
</section>
<!-- Posts Grid -->
<section class="posts-container">
<div class="container">
<div class="row g-4" id="postsGrid"></div>
</div>
</section>
<!-- Create Post Modal -->
<div class="modal fade" id="createPostModal" tabindex="-1" aria-labelledby="createPostModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="createPostModalLabel">
<i class="fas fa-pen-fancy me-2"></i>Create New Post
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body p-4">
<form id="createPostForm">
<div class="mb-3">
<label for="postTitle" class="form-label">
<i class="fas fa-heading me-2 text-primary"></i>Post Title
</label>
<input type="text" class="form-control" id="postTitle" placeholder="Enter an engaging title..." required>
</div>
<div class="mb-3">
<label for="postAuthor" class="form-label">
<i class="fas fa-user-edit me-2 text-success"></i>Author Name
</label>
<input type="text" class="form-control" id="postAuthor" placeholder="Your name..." required>
</div>
<div class="mb-3">
<label for="postCategory" class="form-label">
<i class="fas fa-tag me-2 text-warning"></i>Category
</label>
<select class="form-select" id="postCategory" required>
<option value="">Select a category...</option>
<option value="Technology">Technology</option>
<option value="Programming">Programming</option>
<option value="Design">Design</option>
<option value="Photography">Photography</option>
<option value="Lifestyle">Lifestyle</option>
<option value="Travel">Travel</option>
</select>
</div>
<div class="mb-3">
<label for="postImage" class="form-label">
<i class="fas fa-image me-2 text-info"></i>Image URL
</label>
<input type="url" class="form-control" id="postImage" placeholder="https://example.com/image.jpg"
required>
</div>
<div class="mb-4">
<label for="postDescription" class="form-label">
<i class="fas fa-align-left me-2 text-danger"></i>Description
</label>
<textarea class="form-control" id="postDescription" rows="4" placeholder="Write your post content here..."
required></textarea>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-submit-post">
<i class="fas fa-paper-plane me-2"></i>Publish Post
</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script>
<!-- AOS JS -->
<script src="https://unpkg.com/aos@2.3.4/dist/aos.js"></script>
<!-- SWEET ALERT -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- SupaBase Library -->
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
<!-- -->
<script>
AOS.init({
duration: 800,
once: true,
offset: 100
});
// Initialize Supabase
const supabaseUrl = "https://qmujsllexgevhzpkuygo.supabase.co";
const supabaseKey = "sb_publishable_4HLArwo3ZhIorJ15ag0K3Q_o0do1Vk2";
const supabaseClient = supabase.createClient(supabaseUrl, supabaseKey);
let currentUser = null;
let allPosts = [];
// Check auth & navbar avatar
document.addEventListener("DOMContentLoaded", async () => {
await checkAuth();
loadFeedPosts();
});
async function checkAuth() {
try {
const { data: { user }, error } = await supabaseClient.auth.getUser();
if (error || !user) {
window.location.href = "login.html";
return;
}
currentUser = user;
document.getElementById("navbarEmail").textContent = user.email;
const name =
user.user_metadata?.full_name ||
user.email.split("@")[0];
const initials = name.substring(0, 2).toUpperCase();
const avatarUrl = user.user_metadata?.avatar_url || null;
const avatarInitials = document.getElementById("avatarInitials");
const avatarImage = document.getElementById("avatarImage");
avatarInitials.textContent = initials;
if (avatarUrl) {
avatarImage.src = avatarUrl;
avatarImage.style.display = "block";
avatarInitials.style.display = "none";
} else {
avatarImage.style.display = "none";
avatarInitials.style.display = "flex";
}
const postAuthor = document.getElementById("postAuthor");
if (postAuthor) postAuthor.value = name;
} catch (err) {
console.error(err);
window.location.href = "login.html";
}
}
// ============================================
// Load Feed Posts
// ============================================
async function loadFeedPosts() {
const grid = document.getElementById("postsGrid");
if (!grid) return;
grid.innerHTML = `
<div class="text-center py-5">
<div class="spinner-border text-dark"></div>
</div>
`;
const { data: posts, error } = await supabaseClient
.from("posts")
.select("*")
.order("created_at", { ascending: false });
if (error) {
console.error(error);
Swal.fire("Error", "Failed to load feed", "error");
return;
}
allPosts = posts;
renderPosts(posts);
}
// ============================================
// Render Posts with Avatar + Name
// ============================================
function renderPosts(posts) {
const grid = document.getElementById("postsGrid");
grid.innerHTML = "";
if (!posts.length) {
grid.innerHTML = `
<p class="text-center text-danger fs-3">
No posts found
</p>
`;
return;
}
posts.forEach(post => {
const date = new Date(post.created_at).toLocaleDateString("en-US", {
month: "short",
day: "numeric",
year: "numeric"
});
const initials =
post.author_initials ||
post.author?.substring(0, 2).toUpperCase() ||
"?";
grid.innerHTML += `
<div class="col-lg-4 col-md-6" data-aos="fade-up">
<div class="post-card h-100">
<img
src="${post.image_url || ''}"
class="post-image"
onerror="this.onerror=null; this.src='https://via.placeholder.com/600x400?text=No+Image';"
>
<div class="post-content">
<div class="d-flex justify-content-between align-items-start mb-2">
<h3 class="post-title">${post.title}</h3>
<span class="category-badge">${post.category}</span>
</div>
<div class="post-meta mb-3">
<div class="post-author">
<div class="post-avatar">
${post.author_avatar
? `<img src="${post.author_avatar}" alt="avatar">`
: initials
}
</div>
<span>${post.author}</span>
</div>
<span>•</span>
<span>
<i class="fas fa-calendar"></i> ${date}
</span>
</div>
<p class="post-description">
${(post.description || "").substring(0, 120)}...
</p>
<button
class="btn btn-sm btn-dark view-details-btn mt-auto"
data-id="${post.id}">
View details
</button>
</div>
</div>
</div>
`;
});
AOS.refresh();
document.querySelectorAll(".view-details-btn").forEach(btn => {
btn.addEventListener("click", () => {
window.location.href = `post.html?id=${btn.dataset.id}`;
});
});
}
// ============================================
// Category Filter
// ============================================
document.getElementById("categoryFilter").addEventListener("change", () => {
const selectedCategory = categoryFilter.value;
if (selectedCategory === "all") {
renderPosts(allPosts);
} else {
renderPosts(
allPosts.filter(post => post.category === selectedCategory)
);
}
});
</script>
</body>
</html>