Skip to content

Commit

Permalink
collapsible recent activity, and improvements to comment layout
Browse files Browse the repository at this point in the history
  • Loading branch information
mawise committed Jul 21, 2024
1 parent 75f1dc7 commit 72be07d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
27 changes: 27 additions & 0 deletions app/assets/stylesheets/misc.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,30 @@ p.indie-client-name {
span.indie-auth-client {
font-weight: bold;
}

details.recent_activity summary h2 {
display: inline-block;
padding-top: 0.25rem;
}

details.recent_activity summary {
cursor: pointer;
list-style: none;
}

details.recent_activity div p:last-child {
margin-bottom: 0;
}

details.recent_activity[open] summary h2:before {
content: "▼ ";
font-size: 0.7em;
}
details.recent_activity summary h2:before {
content: "► ";
font-size: 0.7em;
}

span.reaction_age {
font-size: small;
}
10 changes: 10 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@ class User < ApplicationRecord
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable

def display_name
if self.name.nil?
return self.email
elsif self.name.empty?
return self.email
else
return self.name
end
end
end
11 changes: 7 additions & 4 deletions app/views/posts/_activity.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<% if @recent_comments_and_likes.size > 0 %>
<h2>Recent Activity</h2>
<details open class="recent_activity">
<summary><h2>Recent Activity</h2></summary>
<div>
<% @recent_comments_and_likes.each do |reaction| %>
<p>
<% if reaction.is_a? Like %>
<p><%= time_ago_in_words(reaction.created_at) %> ago, <%= reaction.reaction %> from <%= reaction.user.name %> on <%= link_to PostsController.make_slug(reaction.post.content).titleize, reaction.post %></p>
<%= reaction.reaction %> from <%= reaction.user.display_name %> on <%= link_to PostsController.make_slug(reaction.post.content).titleize, reaction.post %>
<% elsif reaction.is_a? Comment %>
<p><%= time_ago_in_words(reaction.created_at) %> ago, <%= reaction.author.name %> commented on <%= link_to PostsController.make_slug(reaction.post.content).titleize, reaction.post %></p>
<%= reaction.author.display_name %> commented on <%= link_to PostsController.make_slug(reaction.post.content).titleize, reaction.post %>
<% end %>
<span class="reaction_age"><%= time_ago_in_words(reaction.created_at) %> ago</span></p>
<% end %>
</div>
<hr>
</details>
<% end %>
4 changes: 2 additions & 2 deletions app/views/posts/_posts.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
</p><%= post.like_text %></p>
<% end %>
<% post.comments.each do |comment| %>
<small><%=comment.author.name%></small>
<small><%=comment.author.name%>: </small> <%= comment.body %>
<% if current_user.admin == 1 || (current_user.admin == 2 and post.author == current_user) %>
<span style="float: right;">
<%= link_to 'Delete', destroy_comment_path(comment),
method: :delete,
data: { confirm: 'Are you sure you want to delete this comment?' } %>
</span>
<% end %>
<br/><%= comment.body %><br/>
<br/>
<% end %>
<br<%= show_page ? raw(' id="comment_form"') : raw(" id=\"comment_form_#{post.id}\"") %>/>
<div>
Expand Down

0 comments on commit 72be07d

Please sign in to comment.