Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
143 lines (119 loc) · 4.37 KB
/
Copy pathindex.js
File metadata and controls
143 lines (119 loc) · 4.37 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
const posts = [
{
name: "Vincent van Gogh",
username: "vincey1853",
location: "Zundert, Netherlands",
avatar: "/images/avatar-vangogh.jpg",
post: "/images/post-vangogh.jpg",
comment: "just took a few mushrooms lol",
likes: 21,
},
{
name: "Gustave Courbet",
username: "gus1819",
location: "Ornans, France",
avatar: "/images/avatar-courbet.jpg",
post: "/images/post-courbet.jpg",
comment: "i'm feelin a bit stressed tbh",
likes: 4,
},
{
name: "Joseph Ducreux",
username: "jd1735",
location: "Paris, France",
avatar: "/images/avatar-ducreux.jpg",
post: "/images/post-ducreux.jpg",
comment:
"gm friends! which coin are YOU stacking up today?? post below and WAGMI!",
likes: 152,
},
];
const postFeed = document.querySelector(".feed");
for (let i = 0; i < posts.length; i++) {
const post = posts[i];
const articlePost = document.createElement("article");
articlePost.classList.add("posts-container");
postFeed.append(articlePost);
const contentHeader = document.createElement("header");
contentHeader.classList.add("content-header");
articlePost.append(contentHeader);
const userHeader = document.createElement("div");
userHeader.classList.add("user-header");
contentHeader.append(userHeader);
const userAvatar = document.createElement("img");
userAvatar.classList.add("user-avatar");
userAvatar.src = post.avatar;
userHeader.append(userAvatar);
const userInfo = document.createElement("div");
userInfo.classList.add("user-info");
contentHeader.append(userInfo);
const contentHeaderH1 = document.createElement("h1");
contentHeaderH1.classList.add("content-header-h1");
contentHeaderH1.textContent = post.name;
userInfo.append(contentHeaderH1);
const contentHeaderParagraph = document.createElement("p");
contentHeaderParagraph.classList.add("content-header-paragraph");
contentHeaderParagraph.textContent = post.location;
userInfo.append(contentHeaderParagraph);
const figure = document.createElement("figure");
articlePost.append(figure);
const postImg = document.createElement("img");
postImg.classList.add("post-img");
postImg.src = post.post;
figure.append(postImg);
const postActions = document.createElement("section");
postActions.classList.add("post-actions");
articlePost.append(postActions);
const likeBtn = document.createElement("button");
likeBtn.classList.add("action-btn");
const heartIcon = document.createElement("img");
heartIcon.classList.add("heart-icon");
heartIcon.src = "/images/icon-heart.png";
heartIcon.width = 28;
heartIcon.height = 30;
likeBtn.append(heartIcon);
let isLiked = false;
likeBtn.addEventListener("click", () => {
if (isLiked) {
post.likes = post.likes - 1;
} else {
post.likes = post.likes + 1;
}
isLiked = !isLiked;
likeCount.textContent = post.likes + " likes";
likeBtn.setAttribute("aria-pressed", isLiked);
});
const commentBtn = document.createElement("button");
commentBtn.classList.add("action-btn");
const commentIcon = document.createElement("img");
commentIcon.classList.add("comment-icon");
commentIcon.src = "/images/icon-comment.png";
commentIcon.width = 30;
commentIcon.height = 30;
commentBtn.append(commentIcon);
const messagetBtn = document.createElement("button");
messagetBtn.classList.add("action-btn");
const messageIcon = document.createElement("img");
messageIcon.classList.add("message-icon");
messageIcon.src = "/images/icon-dm.png";
messageIcon.width = 26;
messageIcon.height = 26;
messagetBtn.append(messageIcon);
postActions.append(likeBtn, commentBtn, messagetBtn);
const postDataSection = document.createElement("section");
postDataSection.classList.add("post-data");
articlePost.append(postDataSection);
const likeCount = document.createElement("span");
likeCount.classList.add("like-count");
likeCount.textContent = post.likes + " " + "likes";
postDataSection.append(likeCount);
const postCommentSection = document.createElement("section");
postCommentSection.classList.add("post-comment");
articlePost.append(postCommentSection);
const comment = document.createElement("span");
comment.classList.add("comment");
const usernameBold = document.createElement("b");
usernameBold.textContent = post.username;
comment.append(usernameBold, " " + post.comment);
postCommentSection.append(comment);
}