-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_post.ejs
58 lines (40 loc) · 1.5 KB
/
_post.ejs
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
<li id="post-<%= post._id %>">
<p>
<% if (locals.user && (locals.user.id== post.user.id)){ %>
<small>
<a class="delete-post-button" href="/post/destroy/<%= post.id %>" >X</a>
</small>
<%}%>
<%= post.content %>
<br/>
<small><%= post.user.name %></small>
<!-- CHANGE :: display the likes of this post, if the user is logged in, then show the link to toggle likes, else, just show the count -->
<br>
<!-- study about the data attribute -->
<small>
<% if (locals.user){ %>
<a class="toggle-like-button" data-likes="<%= post.likes.length %>" href="/likes/toggle/?id=<%=post._id%>&type=Post">
<%= post.likes.length %> Likes
</a>
<% }else{ %>
<%= post.likes.length %> Likes
<% } %>
</small>
</p>
<div class="post-comments">
<% if(locals.user) {%>
<form id="post-<%= post._id %>-comments-form" action="/comment/create" method="post">
<input type="text" name="content" placeholder="Type here to add comment..." required>
<input type="hidden" name="post" value="<%= post._id%>" >
<input type="submit" value="Add value">
</form>
<%}%>
<div id="posts-comments-list" >
<ul id="post-comments-<%= post._id %>">
<% for (comment of post.comments ){%>
<%- include('_comment') -%>
<%}%>
</ul>
</div>
</div>
</li>