From e8eb22a0961e3836038abb127ccb84afe793e883 Mon Sep 17 00:00:00 2001
From: Matthew Wise
Date: Sun, 21 Jul 2024 15:42:28 -0500
Subject: [PATCH] collapsible recent activity, and improvements to comment
layout
---
app/assets/stylesheets/misc.css | 27 +++++++++++++++++++++++++++
app/models/user.rb | 10 ++++++++++
app/views/posts/_activity.html.erb | 11 +++++++----
app/views/posts/_posts.html.erb | 4 ++--
4 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/app/assets/stylesheets/misc.css b/app/assets/stylesheets/misc.css
index 5dcf674..9b4cecb 100644
--- a/app/assets/stylesheets/misc.css
+++ b/app/assets/stylesheets/misc.css
@@ -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;
+}
diff --git a/app/models/user.rb b/app/models/user.rb
index 953a4b6..7669605 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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
diff --git a/app/views/posts/_activity.html.erb b/app/views/posts/_activity.html.erb
index 1e39b8f..a61f6c2 100644
--- a/app/views/posts/_activity.html.erb
+++ b/app/views/posts/_activity.html.erb
@@ -1,13 +1,16 @@
<% if @recent_comments_and_likes.size > 0 %>
-Recent Activity
+
+Recent Activity
<% @recent_comments_and_likes.each do |reaction| %>
+
<% if reaction.is_a? Like %>
-
<%= 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 %>
+ <%= reaction.reaction %> from <%= reaction.user.display_name %> on <%= link_to PostsController.make_slug(reaction.post.content).titleize, reaction.post %>
<% elsif reaction.is_a? Comment %>
-
<%= time_ago_in_words(reaction.created_at) %> ago, <%= reaction.author.name %> commented on <%= link_to PostsController.make_slug(reaction.post.content).titleize, reaction.post %>
+ <%= reaction.author.display_name %> commented on <%= link_to PostsController.make_slug(reaction.post.content).titleize, reaction.post %>
<% end %>
+
<%= time_ago_in_words(reaction.created_at) %> ago
<% end %>
-
+
<% end %>
diff --git a/app/views/posts/_posts.html.erb b/app/views/posts/_posts.html.erb
index 410bb96..54e4728 100644
--- a/app/views/posts/_posts.html.erb
+++ b/app/views/posts/_posts.html.erb
@@ -25,7 +25,7 @@
<%= post.like_text %>
<% end %>
<% post.comments.each do |comment| %>
- <%=comment.author.name%>
+ <%=comment.author.name%>: <%= comment.body %>
<% if current_user.admin == 1 || (current_user.admin == 2 and post.author == current_user) %>
<%= link_to 'Delete', destroy_comment_path(comment),
@@ -33,7 +33,7 @@
data: { confirm: 'Are you sure you want to delete this comment?' } %>
<% end %>
-
<%= comment.body %>
+
<% end %>
/>