15
15
<h1 class =" text-3xl md:text-4xl font-bold text-gray-900" >
16
16
Welcome, <%= locals .user .first_name %> <%= locals .user .last_name %>
17
17
</h1 >
18
+ <a href =" /logout" class =" px-4 py-2 bg-black text-white rounded-md hover:bg-black/80" >Logout</a >
18
19
<div class =" w-20 h-1 bg-blue-500 rounded-full" ></div >
19
20
</div >
20
21
<div class =" feed space-y-8 flex flex-col max-w-4xl mx-auto w-full" >
21
22
<% if (locals .posts .length > 0 ) { % >
22
- < % locals .posts .forEach (post => { % >
23
- < div class = " post bg-white p-6 md:p-8 rounded-xl shadow-sm hover:shadow-md transition-all duration-300 border border-gray-100" >
23
+ < % locals .posts .forEach ( ( post , idx ) => { % >
24
+ < div class = " post bg-white p-6 md:p-8 rounded-xl shadow-sm group hover:shadow-md transition-all duration-300 border border-gray-100" >
24
25
< article class = " space-y-4" >
25
- < h2 class = " text-xl md:text-2xl font-bold text-gray-900 hover:text-blue-600 transition-colors" >
26
+ < h2 class = " text-xl md:text-2xl font-bold text-gray-900 group- hover:text-blue-600 transition-colors" >
26
27
< %= post .title % >
27
28
< / h2>
28
29
< p class = " text-md md:text-lg text-gray-700 leading-relaxed" >
35
36
< path stroke- linecap= " round" stroke- linejoin= " round" stroke- width= " 2" d= " M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" / >
36
37
< / svg>
37
38
< % if (locals .user .is_member || locals .user .id === post .user_id ) { % >
38
- < time class = " text-gray-500" id= " createdAt" data- created- at= " <%= post.created_at %>" >< / time>
39
+ < time class = " text-gray-500 created-at " id= " createdAt" data- created- at= " <%= post.created_at %>" >< / time>
39
40
< % } else { % >
40
41
< a href= " /membership" class = " text-blue-500 hover:text-blue-700 hover:underline font-medium" >
41
42
Membership Required
47
48
< path stroke- linecap= " round" stroke- linejoin= " round" stroke- width= " 2" d= " M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" / >
48
49
< / svg>
49
50
< % if (locals .user .is_member || locals .user .id === post .user_id ) { % >
50
- < span class = " text-gray-500" >< %= user .username % >< / span>
51
+ < span class = " text-gray-500" >< %= postCreators[idx] .username % >< / span>
51
52
< % } else { % >
52
53
< a href= " /membership" class = " text-blue-500 hover:text-blue-700 hover:underline font-medium" >
53
54
Membership Required
93
94
</body >
94
95
<script >
95
96
document .addEventListener (' DOMContentLoaded' , function () {
96
- const createdAtElement = document .getElementById (' createdAt' );
97
- const createdAt = new Date (createdAtElement .getAttribute (' data-created-at' ));
98
- const now = new Date ();
99
- const diffInMs = now - createdAt;
100
- const diffInSecs = Math .floor (diffInMs / 1000 );
101
- const diffInMins = Math .floor (diffInSecs / 60 );
102
- const diffInHours = Math .floor (diffInMins / 60 );
103
- const diffInDays = Math .floor (diffInHours / 24 );
104
- const diffInMonths = Math .floor (diffInDays / 30 );
105
- const diffInYears = Math .floor (diffInDays / 365 );
106
-
107
- let timeAgo = ' ' ;
108
-
109
- if (diffInYears > 0 ) {
110
- timeAgo = diffInYears === 1 ? ' 1 year ago' : ` ${ diffInYears} years ago` ;
111
- } else if (diffInMonths > 0 ) {
112
- timeAgo = diffInMonths === 1 ? ' 1 month ago' : ` ${ diffInMonths} months ago` ;
113
- } else if (diffInDays > 0 ) {
114
- timeAgo = diffInDays === 1 ? ' 1 day ago' : ` ${ diffInDays} days ago` ;
115
- } else if (diffInHours > 0 ) {
116
- timeAgo = diffInHours === 1 ? ' 1 hour ago' : ` ${ diffInHours} hours ago` ;
117
- } else if (diffInMins > 0 ) {
118
- timeAgo = diffInMins === 1 ? ' 1 minute ago' : ` ${ diffInMins} minutes ago` ;
119
- } else {
120
- timeAgo = diffInSecs <= 5 ? ' Just now' : ` ${ diffInSecs} seconds ago` ;
97
+
98
+ // FUNCTIONS //
99
+
100
+ function updatePostTime (){
101
+ const createdAtElement = document .querySelectorAll (' .created-at' );
102
+ createdAtElement .forEach ((element ) => {
103
+ const createdAt = new Date (element .getAttribute (' data-created-at' ));
104
+ const now = new Date ();
105
+ const diffInMs = now - createdAt;
106
+ const diffInSecs = Math .floor (diffInMs / 1000 );
107
+ const diffInMins = Math .floor (diffInSecs / 60 );
108
+ const diffInHours = Math .floor (diffInMins / 60 );
109
+ const diffInDays = Math .floor (diffInHours / 24 );
110
+ const diffInMonths = Math .floor (diffInDays / 30 );
111
+ const diffInYears = Math .floor (diffInDays / 365 );
112
+
113
+ let timeAgo = ' ' ;
114
+
115
+ if (diffInYears > 0 ) {
116
+ timeAgo = diffInYears === 1 ? ' 1 year ago' : ` ${ diffInYears} years ago` ;
117
+ } else if (diffInMonths > 0 ) {
118
+ timeAgo = diffInMonths === 1 ? ' 1 month ago' : ` ${ diffInMonths} months ago` ;
119
+ } else if (diffInDays > 0 ) {
120
+ timeAgo = diffInDays === 1 ? ' 1 day ago' : ` ${ diffInDays} days ago` ;
121
+ } else if (diffInHours > 0 ) {
122
+ timeAgo = diffInHours === 1 ? ' 1 hour ago' : ` ${ diffInHours} hours ago` ;
123
+ } else if (diffInMins > 0 ) {
124
+ timeAgo = diffInMins === 1 ? ' 1 minute ago' : ` ${ diffInMins} minutes ago` ;
125
+ } else {
126
+ timeAgo = diffInSecs <= 5 ? ' Just now' : ` ${ diffInSecs} seconds ago` ;
127
+ }
128
+ element .textContent = timeAgo;
129
+ });
121
130
}
122
-
123
- createdAtElement .textContent = timeAgo;
131
+
132
+ // FUNCTION CALLS //
133
+
134
+ updatePostTime ();
135
+
124
136
});
125
137
</script >
126
138
</html >
0 commit comments