Repository navigation
Expand file tree
/
Copy pathprofile.html
More file actions
438 lines (402 loc) · 21.2 KB
/
Copy pathprofile.html
File metadata and controls
438 lines (402 loc) · 21.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="./imgs/download-removebg-preview (1).png" type="image/x-icon">
<link rel="stylesheet" href="bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="bootstrap-icons/font/bootstrap-icons.css">
<title>Profile</title>
</head>
<style>
@media (max-width:991px) {
.card-body .row {
flex-direction: column;
align-items: center;
justify-content: flex-start;
}
.card-body .row .col-4 {
display: block;
width: 100%;
text-align: center;
}
}
</style>
<body>
<!-- Loader -->
<div id="loder" style="position: fixed; bottom: 0; top: 0; right: 0; left: 0; margin: auto auto; display: flex; justify-content:
center; align-items: center; z-index: 999999; height: 100px; width: 200px; background-color: rgba(128, 128, 128, 0.295); border-radius: 10px;">
<div class="loadingio-spinner-ellipsis-nq4q5u6dq7r"><div class="ldio-x2uulkbinbj">
<div></div><div></div><div></div><div></div><div></div>
</div></div>
</div>
<!-- Loader -->
<!-- Alert -->
<div id="alert" class="show fade" style="position: fixed; right: 0; bottom: 0; width: 90%; z-index: 99999;"></div>
<!-- Modals -->
<!-- Login Modal -->
<div class="modal fade" id="login-modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Login</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form>
<div class="mb-3">
<label for="recipient-name" class="col-form-label userName">Username:</label>
<input type="text" class="form-control" id="username-input" value="nour">
</div>
<div class="mb-3">
<label for="message-text" class="col-form-label passWord">Password:</label>
<input type="password" class="form-control" id="password-input" value="123456">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" onclick="login()">Login</button>
</div>
</div>
</div>
</div>
<!-- Register Modal -->
<div class="modal fade" id="reg-modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Registeration</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form>
<div class="mb-3">
<label for="recipient-name" class="col-form-label">Username:</label>
<input type="text" class="form-control" id="reg-user" placeholder="Enter Username">
</div>
<div class="mb-3">
<label for="recipient-name" class="col-form-label">Password:</label>
<input type="password" class="form-control" id="reg-pass" placeholder="Enter Password">
</div>
<div class="mb-3">
<label for="message-text" class="col-form-label">Name:</label>
<input type="text" class="form-control" id="reg-name" placeholder="Enter Name">
</div>
<div class="mb-3">
<label for="message-text" class="col-form-label">Email:</label>
<input type="email" class="form-control" id="reg-email" placeholder="Email">
</div>
<div class="mb-3">
<label for="message-text" class="col-form-label">Profile Image</label>
<input type="file" class="form-control" id="reg-image" placeholder="Image">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" onclick="register()">Register</button>
</div>
</div>
</div>
</div>
<!-- Add Post & Edit Post Modal -->
<div class="modal fade" id="post-modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="post-modal-title">Create A New Post</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form>
<div class="mb-3">
<label for="recipient-name" class="col-form-label">Title:</label>
<input type="text" class="form-control" id="post-title">
<!-- Checker for Edit Or Create -->
<input type="hidden" id="post-id-input" value="">
</div>
<div class="mb-3">
<textarea class="form-control" style="resize: none;" id="post-body"></textarea>
</div>
<div class="mb-3">
<label for="recipient-name" class="col-form-label">Image</label>
<input type="file" class="form-control" id="post-image">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" onclick="createPost()" id="editOrCreate">Create</button>
</div>
</div>
</div>
</div>
<!-- Delete modal -->
<div class="modal fade" id="delete-modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="delete-modal-title">Are You Sure?</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form>
<div class="mb-3">
<label for="recipient-name" class="col-form-label">You Can't Get Your Post Back Again !</label>
<input type="hidden" id="post-delete-con" value="">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">I'm Kidding</button>
<button type="button" class="btn btn-danger" onclick="sureDeleteBtn()" >Delete</button>
</div>
</div>
</div>
</div>
<!-- Nav Bar Start -->
<div class="container d-flex justify-content-center">
<div class="col-lg-9 col-sm-11 col-12">
<nav class="navbar navbar-expand-lg bg-body-tertiary shadow p-2 mb-5 bg-body-tertiary rounded">
<div class="container-fluid">
<a class="navbar-brand" href="index.html">Sharea</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" onclick="currentUser()" style="cursor: pointer;">Profile</a>
</li>
</ul>
<button type="button" data-bs-toggle="modal" data-bs-target="#login-modal" class="btn btn-outline-success me-2" id="log-btn"
>Login</button>
<img src="" id="imageNav" alt="" style="width: 40px;" class="border border-primary-subtle rounded-circle border-2 me-2">
<span class="me-3" id="userNav"></span>
<button type="button" class="btn btn-outline-danger" onclick="logout()" id="logout-btn">Logout</button>
<button type="button" class="btn btn-outline-success me-1" data-bs-toggle="modal" data-bs-target="#reg-modal" id="reg-btn">Register</button>
</div>
</div>
</nav>
</div>
</div>
<!-- Nav Bar End -->
<!-- Start the main info -->
<div class="container d-flex justify-content-center">
<div id="info" class="col-lg-9 col-sm-11 col-12">
<!-- User Info -->
<h1 class="mb-4">
<span id="user-head">
Nour's
</span>
Profile
</h1>
<div class="card shadow">
<div class="card-body">
<div class="row">
<div class="col-4">
<img id="user-img" src="./imgs/download-removebg-preview (1).png" alt="" style="width: 200px; height: 200px; border-radius: 50%;">
</div>
<div class="col-4 d-flex flex-column justify-content-evenly fs-4">
<div id="user-email">Email: Email@gmail.com</div>
<div id="username"> @username</div>
<div id="user-name">His Name</div>
</div>
<div class="col-4 d-flex flex-column justify-content-evenly big-nums">
<div> <span id="post-count">3</span> Posts</div>
<div> <span id="comments-count">10</span> Comments</div>
</div>
</div>
</div>
</div>
<div>
<h1 id="user-post-own" class="mt-5 mb-5" >nour post</h1>
</div>
<!-- User Info -->
<!-- Posts -->
<div id="posts">
<div class="card shadow mb-5">
<div class="card-header">
<img src="./imgs/download-removebg-preview (1).png" alt="" style="width: 40px;" class="border border-primary-subtle rounded-circle border-1">
<b class="ms-2">@nour</b>
</div>
<div class="card-body" style="cursor:pointer;">
<img src="./imgs/shuffle-02.jpg" class="w-100" alt="">
<div class="text-secondary mt-1">2 min ago</div>
<h5 class="mt-2">Title</h5>
<p>best body</p>
<hr>
<div class="card-footer">
<i class="bi bi-vector-pen align-bottom"></i>
<span>
(3) Comments
</span>
<span id="post-tags">
<button class="tag btn btn-sm btn-secondary rounded-5 ms-1 pe-none">Sports</button>
</span>
</div>
</div>
</div>
</div>
<!-- Posts -->
</div>
<!-- end the main info -->
</body>
<!-- Outside JavaScript -->
<script src="bootstrap.bundle.min.js"></script>
<script src="axios.min.js"></script>
<script src="main.js"></script>
<!-- Outside JavaScript -->
<!-- Inside JavaScript -->
<script>
setupUI()
getUserInfo()
let urlParam = new URLSearchParams(window.location.search)
let userId = urlParam.get("Id")
getUserInfo(userId)
getPosts(userId)
function getUserInfo(userId) {
axios.get(`${baseURL}/users/${userId}`)
.then((response) => {
let user = response.data.data
document.getElementById("user-email").innerHTML = `Email: ${user.email}`
document.getElementById("username").innerHTML = `Username: ${user.username}`
document.getElementById("user-name").innerHTML = `Name: ${user.name}`
document.getElementById("user-head").innerHTML = user.name
document.getElementById("post-count").innerHTML = user.posts_count
document.getElementById("user-img").src = user.profile_image || "./imgs/download-removebg-preview (1).png";
document.getElementById("comments-count").innerHTML = user.comments_count
})
}
function getPosts(id) {
axios.get(`${baseURL}/users/${id}/posts`)
.then(function (response) {
toggleLoder(false)
let posts = response.data.data
let postTitle = '';
let userimage = ''
document.getElementById("posts").innerHTML = ""
// (for of) Method
for(post of posts) {
// Check the title
if (post.title != null) {
postTitle = post.title
}
// Check the user
let userInfoId = getUserName();
let isThisUser = userInfoId != null && userInfoId.id == post.author.id;
let editContent = '';
if(isThisUser) {
editContent = `
<div style="float:right; font-size:20px; cursor:pointer;" onclick="editPost(this)"
data-post="${encodeURIComponent(JSON.stringify(post))}"><i class="bi bi-pencil-square"></i>
</div>
<div style="float:right; font-size:20px; cursor:pointer; margin-right:15px;"
onclick="deletePost(this)"
data-post="${encodeURIComponent(JSON.stringify(post))}"><i class="bi bi-trash3"></i>
</div>
`}
// The content
let content = `
<div class="card shadow mb-5">
<div class="card-header">
<img src="${post.author.profile_image}" alt="" style="width: 40px;" class="border border-primary-subtle rounded-circle border-1">
<b class="ms-2">${post.author.username}</b>
${editContent}
</div>
<div class="card-body" onclick= "postDetails(${post.id})" style="cursor:pointer;">
<img src="${post.image}" class="w-100" alt="">
<div class="text-secondary mt-1">${post.created_at}</div>
<h5 class="mt-2">${postTitle}</h5>
<p>${post.body}</p>
<hr>
<div class="card-footer">
<i class="bi bi-vector-pen align-bottom"></i>
<span>
(${post.comments_count}) Comments
</span>
<span id="post-tags">
<button class="tag btn btn-sm btn-secondary rounded-5 ms-1 pe-none">Sports</button>
</span>
</div>
</div>
`
document.getElementById("user-post-own").innerHTML = `${post.author.username}'s Posts`
document.getElementById("posts").innerHTML += content
}});
}
// Edit Buttons
function editPost(btn) {
// Post object with all the info
let postInfo = JSON.parse(decodeURIComponent(btn.dataset.post));
// Edit innerHtml Title
document.getElementById("post-modal-title").innerHTML = "Edit Post"
// Make a copy of the reg-modal for edit
let editPostModal = new bootstrap.Modal(document.getElementById("post-modal"),{})
editPostModal.toggle()
document.getElementById("post-id-input").value = postInfo.id
// Edit the post itself
document.getElementById("editOrCreate").innerHTML = "Update"
document.getElementById("post-title").value = postInfo.title
document.getElementById("post-body").value = postInfo.body
getPosts(userId)
}
function deletePost(btn) {
// Post object with all the info
let postInfo = JSON.parse(decodeURIComponent(btn.dataset.post));
// Make a copy of the reg-modal for edit
document.getElementById("post-delete-con").value = postInfo.id
let deletePostModal = new bootstrap.Modal(document.getElementById("delete-modal"),{})
deletePostModal.toggle()
}
function sureDeleteBtn() {
let token = localStorage.getItem("token")
let postId = document.getElementById("post-delete-con").value;
axios.delete(`https://tarmeezacademy.com/api/v1/posts/${postId}` , {
headers: {
authorization: `Bearer ${token}`
}
}).then((res)=> {
let deleteModal = document.getElementById("delete-modal")
let modalInstance = bootstrap.Modal.getInstance(deleteModal)
modalInstance.hide()
showAlert('Your Post Has Been Deleted', "success" ,'alert')
getPosts(userId)
})
}
// console.log(userData)
// let userEmail = ''
// if(userData.email != null) {
// userEmail = `<div id="user-email">${userData.email}</div>`
// } else{
// userEmail = "*Email Is Private*"
// }
// let content = ` <h1 class="mb-4">
// <span>
// ${userData.name}'s
// </span>
// Profile
// </h1>
// <div class="card shadow">
// <div class="card-body">
// <div class="row">
// <div class="col-4">
// <img id="user-img" src=" ${userData.profile_image}" alt="">
// </div>
// <div class="col-4 d-flex flex-column justify-content-evenly fs-4">
// <div id="user-email">${userEmail}</div>
// <div id="username"> ${userData.username}</div>
// <div id="user-name"> ${userData.name}</div>
// </div>
// <div class="col-4 d-flex flex-column justify-content-evenly big-nums">
// <div> <span id="post-count"> ${userData.posts_count}</span> Posts</div>
// <div> <span id="comments-count"> ${userData.comments_count}</span> Comments</div>
// </div>
// </div>
// </div>
// document.getElementById("info").innerHTML = content
</script>
<!-- Inside JavaScript -->
</html>