-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
152 lines (114 loc) · 4.91 KB
/
index.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
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
import avatar1 from './images/avatar-vangogh.jpg';
import avatar2 from './images/avatar-courbet.jpg';
import avatar3 from './images/avatar-ducreux.jpg';
import post1 from './images/post-vangogh.jpg';
import post2 from './images/post-courbet.jpg';
import post3 from './images/post-ducreux.jpg';
import heart from './images/icon-heart.png';
import comment from './images/icon-comment.png';
import dm from './images/icon-dm.png';
import redHeart from './images/red-heart.png';
const posts = [
{
name: "Vincent van Gogh",
username: "vincey1853",
location: "Zundert, Netherlands",
avatar: avatar1,
post: post1,
comment: "just took a few mushrooms lol",
likes: 21
},
{
name: "Gustave Courbet",
username: "gus1819",
location: "Ornans, France",
avatar: avatar2,
post: post2,
comment: "i'm feelin a bit stressed tbh",
likes: 4
},
{
name: "Joseph Ducreux",
username: "jd1735",
location: "Paris, France",
avatar: avatar3,
post: post3,
comment: "gm friends! which coin are YOU stacking up today?? \npost below and WAGMI!",
likes: 152
}
]
const postsEl = document.getElementById("all-posts");
function postElements() { /*...*/
for (let i = 0; i < posts.length; i++) {
postsEl.innerHTML += `<section class="container flex">
<img src="${posts[i].avatar}" class="img-round avatar">
<span>
<h1>${posts[i].name}</h2>
<p>${posts[i].location}</p>
</span>
</section>
<section class="container" >
<img src="${posts[i].post}" class="img-post" alt="image of ${posts[i].post}>
</section>
<section class="container">
<div class="flex space">
<input id="btn-heart" type="button" class="icon heart" alt="Submit" role="icon" aria-label="a icon heart like button">
<img src="${comment}" class="icon">
<img src="${dm}" class="icon">
</div>
<h2 class="space likes">${posts[i].likes} likes</h2>
<p class="padding-btm space"><span class="bold">${posts[i].username}</span> ${posts[i].comment}</p>
</section>`;
};
let numberOfLikesElement = document.getElementsByClassName("likes");
posts.forEach((post, index) => {
let allInputs = document.querySelectorAll("input");
allInputs[index].addEventListener("click", function (e) {
e.preventDefault();
const btnHeart = document.getElementsByClassName("heart");
// btnHeart[index].classList.toggle("toggleHeart");
btnHeart[index].style = `background: url('${redHeart}') center / cover no-repeat; height: 30px`
let counts = post.likes + 1;
numberOfLikesElement[index].innerHTML = `${counts} likes`;
});
})
};
document.onload = postElements()
// const postEl = document.getElementById("post-el")
// const users = posts.map((post, index) => {
// let section = document.createElement("section");
// section.className = "container flex";
// section.innerHTML =` <img src="${post.avatar}" class="img-round">
// <span>
// <h1>${post.name}</h2>
// <p>${post.location}</p>
// </span>`;
// postEl.append(section);
// let section2 = document.createElement("section");
// section2.className = "container";
// section2.innerHTML = `<img src="${post.post}" class="img-post">`;
// postEl.appendChild(section2);
// let section3 = document.createElement("section");
// section3.className = "container";
// section3.innerHTML = `
// <div class="flex space">
// <input id="btn-heart" type="image" src="images/icon-heart.png" class="icon heart" alt="Submit">
// <img src="images/icon-comment.png" class="icon">
// <img src="images/icon-dm.png" class="icon">
// </div>
// <h2 class="space likes">${post.likes} likes</h2>
// <p class="padding-btm space"><span class="bold">${post.username} </span>${post.comment}</p>`;
// postEl.append(section3);
// const btnHeart = document.getElementById("btn-heart");
// let likesEl = document.getElementsByClassName("likes");
// let counts = post.likes
// let allInputs = document.querySelectorAll("input");
// allInputs[index].addEventListener("click", function(e){
// counts = counts + 1
// likesEl[index].innerHTML = `${counts} likes`;
// });
// });
// //loads function when page loads
// window.onload('load', () => {
// return users;
// })