-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmy_posts.html
More file actions
224 lines (199 loc) · 6.72 KB
/
my_posts.html
File metadata and controls
224 lines (199 loc) · 6.72 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Posts - Simple Blog</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
}
.header {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
padding: 1rem 2rem;
color: white;
}
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
max-width: 1200px;
margin: 0 auto;
}
.nav-brand {
font-size: 1.5rem;
font-weight: bold;
color: white;
text-decoration: none;
}
.nav-links {
display: flex;
gap: 2rem;
list-style: none;
}
.nav-links a {
color: white;
text-decoration: none;
}
.btn {
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
text-decoration: none;
display: inline-block;
}
.btn-primary {
background: #667eea;
color: white;
}
.btn-danger {
background: #ef4444;
color: white;
}
.container {
max-width: 1200px;
margin: 2rem auto;
padding: 0 2rem;
}
.content-box {
background: white;
padding: 2rem;
border-radius: 10px;
box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}
.post-card {
background: #f8fafc;
padding: 1.5rem;
border-radius: 10px;
margin-bottom: 1rem;
border-left: 4px solid #667eea;
}
.post-actions {
margin-top: 1rem;
display: flex;
gap: 1rem;
}
.empty-state {
text-align: center;
padding: 3rem;
color: #6b7280;
}
</style>
</head>
<body>
<header class="header">
<nav class="navbar">
<a href="/" class="nav-brand">Simple Blog</a>
<ul class="nav-links">
<li><a href="/">Home</a></li>
<li><a href="/dashboard">Dashboard</a></li>
<li><a href="/create-post">Create Post</a></li>
<li><a href="/my-posts">My Posts</a></li>
<li><button onclick="logout()" class="btn btn-danger">Logout</button></li>
</ul>
</nav>
</header>
<div class="container">
<div class="content-box">
<h1>My Posts</h1>
<p>Manage your blog posts here.</p>
<div style="text-align: right; margin: 1rem 0;">
<a href="/create-post" class="btn btn-primary">Create New Post</a>
</div>
<div id="posts-container">
<div class="empty-state">
<h3>No posts yet</h3>
<p>Create your first post to get started!</p>
<a href="/create-post" class="btn btn-primary">Create First Post</a>
</div>
</div>
</div>
</div>
<script>
// Load user's posts
function loadMyPosts() {
fetch('/api/posts')
.then(response => response.json())
.then(data => {
if (data.success && data.posts.length > 0) {
displayPosts(data.posts);
}
})
.catch(error => {
console.error('Error loading posts:', error);
});
}
function displayPosts(posts) {
const container = document.getElementById('posts-container');
container.innerHTML = '';
posts.forEach(post => {
const postElement = document.createElement('div');
postElement.className = 'post-card';
postElement.innerHTML = `
<h3>${post.title}</h3>
<p>${post.content.substring(0, 100)}...</p>
<div class="post-meta">
<small>Created: ${new Date(post.created_at).toLocaleDateString()}</small>
</div>
<div class="post-actions">
<button onclick="viewPost(${post.id})" class="btn btn-primary">View</button>
<button onclick="editPost(${post.id})" class="btn" style="background: #f59e0b; color: white;">Edit</button>
<button onclick="deletePost(${post.id})" class="btn btn-danger">Delete</button>
</div>
`;
container.appendChild(postElement);
});
}
function viewPost(postId) {
window.location.href = `/post/${postId}`;
}
function editPost(postId) {
window.location.href = `/edit/${postId}`;
}
function deletePost(postId) {
if (confirm('Are you sure you want to delete this post?')) {
fetch(`/api/posts/${postId}`, {
method: 'DELETE'
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('Post deleted successfully!');
loadMyPosts();
} else {
alert('Error deleting post: ' + data.message);
}
})
.catch(error => {
console.error('Error:', error);
alert('Error deleting post');
});
}
}
function logout() {
if (confirm('Are you sure you want to logout?')) {
fetch('/api/auth/logout', {
method: 'POST'
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.location.href = '/login';
}
});
}
}
// Load posts when page loads
loadMyPosts();
</script>
</body>
</html>