-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.html
More file actions
264 lines (229 loc) · 8.31 KB
/
post.html
File metadata and controls
264 lines (229 loc) · 8.31 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Post Details</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- SweetAlert2 -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<style>
body {
background-color: #f8f9fa;
font-family: "Poppins", sans-serif;
}
/* 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;
}
.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;
background: linear-gradient(135deg, #d946ef 0%, #a855f7 100%);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: 600;
font-size: 1rem;
cursor: pointer;
transition: transform 0.3s ease;
}
.user-avatar:hover {
transform: scale(1.1);
}
/* Post Card Styles */
.post-container {
max-width: 900px;
margin: 60px auto;
}
.post-card {
background: #ffffff;
border-radius: 16px;
padding: 30px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
}
/* Title */
#postTitle {
font-size: 2rem;
font-weight: 700;
color: #1e293b;
margin-bottom: 10px;
}
/* Author & Date */
#postAuthorDate {
font-size: 0.9rem;
color: #64748b;
margin-bottom: 20px;
}
/* Image */
#postImage {
width: 100%;
max-height: 420px;
object-fit: cover;
border-radius: 14px;
margin-bottom: 20px;
}
/* Category badge */
#postCategory {
background: linear-gradient(135deg, #d946ef, #a855f7);
font-size: 0.8rem;
padding: 6px 14px;
border-radius: 20px;
margin-bottom: 20px;
display: inline-block;
}
/* Description */
#postDescription {
font-size: 1rem;
line-height: 1.8;
color: #334155;
}
/* Back Button */
.back-btn {
margin-top: 30px;
display: inline-block;
text-decoration: none;
font-weight: 600;
color: #1e293b;
border: 2px solid #1e293b;
padding: 8px 20px;
border-radius: 8px;
transition: all 0.3s ease;
}
.back-btn:hover {
background-color: #1e293b;
color: #ffffff;
}
</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="">
</div>
POST App
</a>
<div class="user-info ms-auto">
<!-- Add this element to display the email dynamically -->
<span class="user-email d-none d-md-inline" id="navbarEmail">Loading...</span>
<div class="user-avatar" data-bs-toggle="dropdown" aria-expanded="false" id="userAvatar">
?
</div>
<ul class="dropdown-menu dropdown-menu-end">
<li><a class="dropdown-item" href="#"><i class="fas fa-user me-2"></i>Profile</a></li>
<li><a class="dropdown-item" href="#"><i class="fas fa-cog me-2"></i>Settings</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item text-danger" href="login.html"><i
class="fas fa-sign-out-alt me-2"></i>Logout</a>
</li>
<a href="signup.html"><button class="post-btn">Post Now</button></a>
</ul>
</div>
</div>
</nav>
<!-- -->
<div class="container post-container">
<div class="post-card">
<h2 id="postTitle">Loading...</h2>
<p class="text-muted" id="postAuthorDate"></p>
<p><span class="badge" id="postCategory"></span></p>
<img id="postImage" class="img-fluid mb-3" src="" alt="Post Image">
<hr>
<p id="postDescription" style="white-space: pre-line;"></p>
</div>
</div>
<!-- SupaBase Library -->
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
<!-- -->
<script>
// Initialize Supabase
const supabaseUrl = "https://qmujsllexgevhzpkuygo.supabase.co";
const supabaseKey = "sb_publishable_4HLArwo3ZhIorJ15ag0K3Q_o0do1Vk2";
const supabaseClient = supabase.createClient(supabaseUrl, supabaseKey);
// Declare currentUser for access in checkAuth
let currentUser;
document.addEventListener("DOMContentLoaded", async () => {
await checkAuth();
loadPost();
});
async function checkAuth() {
try {
const { data: { user }, error } = await supabaseClient.auth.getUser();
if (error || !user) {
window.location.href = "signup.html";
return;
}
currentUser = user;
// Update navbar email dynamically
const navbarEmail = document.getElementById("navbarEmail");
if (navbarEmail) {
navbarEmail.textContent = user.email || "user@example.com";
}
const userAvatarElement = document.getElementById('userAvatar');
if (userAvatarElement) {
const initials = user.email.substring(0, 2).toUpperCase();
userAvatarElement.textContent = initials;
// Set avatar image if available
if (user.avatar_url) {
userAvatarElement.style.backgroundImage = `url(${user.avatar_url})`;
}
}
} catch (error) {
console.error("Error checking auth:", error);
}
}
async function loadPost() {
const params = new URLSearchParams(window.location.search);
const postId = params.get('id');
if (!postId) {
Swal.fire({ icon: 'error', title: 'Error', text: 'Post ID not found!' });
return;
}
const { data: post, error } = await supabaseClient
.from('posts')
.select('*')
.eq('id', postId)
.single();
if (error || !post) {
Swal.fire({ icon: 'error', title: 'Error', text: error?.message || 'Post not found!' });
return;
}
// Populate the post details in the page
document.getElementById('postTitle').textContent = post?.title || 'Untitled Post';
document.getElementById('postAuthorDate').textContent = `By ${post?.author || 'Unknown'} • ${new Date(post?.created_at).toLocaleDateString()}`;
document.getElementById('postImage').src = post?.image_url || 'img/no-image.png';
document.getElementById('postImage').alt = post?.title;
document.getElementById('postCategory').textContent = post?.category || 'General';
document.getElementById('postDescription').textContent = post?.description || 'No description available';
}
</script>
</body>
</html>