-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.js
105 lines (81 loc) · 2.85 KB
/
profile.js
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
setupUi()
// logoud()
//
function getuserId(){
const urlParams = new URLSearchParams(window.location.search)
const id =urlParams.get("userid")
return id
}
getUserPost=()=>{
let id = getuserId()
// alert(id)
// return
axios.get(`https://tarmeezacademy.com/api/v1/users/${id}`)
.then((response)=>{
let users = response.data.data
console.log(users)
document.getElementById("name").innerHTML =users.username
// heder
document.getElementById("user-email").innerHTML =`Gmail:${users.email}`
document.getElementById("user-name").innerHTML =`User_Name:${users.username}`
document.getElementById("user-age").innerHTML =`Name:${users.name}`
// posts
document.getElementById("user-number-post").innerHTML =users.posts_count
document.getElementById("user-number-comment").innerHTML =users.comments_count
document.getElementById("user-img").src =users.profile_image
}).catch((err)=>{
console.log(err)
})
}
getUserPost()
getpostuserPage=()=>{
let id = getuserId()
axios.get(`https://tarmeezacademy.com/api/v1/users/${id}/posts`)
.then((response)=>{
let posts = response.data.data
// if (relode) {
document.getElementById("oooo").innerHTML = ""
// }
for(post of posts){
console.log(post)
let user = getCurrentuser()
let ismyPost =user !=null && post.author.id == user.id
let buttoncontent =``
let deletebtn =``
if(ismyPost){
buttoncontent = ` <button onclick="editonclick('${encodeURIComponent(JSON.stringify(post))}')" class="btn btn-primary float-end" style=" margin : 7px;">edit</button>`
deletebtn = ` <button onclick="deleteonclick('${encodeURIComponent(JSON.stringify(post))}')" class="btn btn-danger float-end" style=" margin : 7px;">delet</button>`
}
let contents =`
<div class="card">
<div class="card-header">
<div class="hed d-flex justify-content-between shadow-lg mb-2">
<div style="cursor: pointer;">
<img id="img-profile" style="width: 40px; height: 40px; object-fit: cover;" class=" m-2 rounded-circle " src="${post.author.profile_image}">
<span>${post.author.username}</span>
</div>
<div>
${buttoncontent}
${deletebtn}</div>
</div>
</div>
<div class="card-body" onclick="postcliced(${post.id})">
<img class="w-100 " src="${post.image}"/>
<h6>${post.created_at}</h6>
<h4>${post.author.name}</h4>
<h5>${post.body}</h5>
<hr>
<span>
<i class="fa-regular fa-comment"></i> comimnts
</span>
</div>
</div>
`
document.getElementById("oooo").innerHTML += contents
}
}).catch((err)=>{
console.log(err)
})
}
getpostuserPage()
// rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr