From 09cc76c4f7e26bdc49a9529008d123cb587f58cb Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Wed, 14 Aug 2024 17:36:13 -0500 Subject: [PATCH] Render comments on splats --- app/assets/stylesheets/comments.css | 6 +++ app/controllers/comments_controller.rb | 2 + app/helpers/comments_helper.rb | 2 + app/models/comment.rb | 4 ++ app/models/splat.rb | 1 + app/models/user.rb | 4 ++ app/views/comments/_comment.html.erb | 13 +++++ app/views/splats/show.html.erb | 52 +------------------- db/migrate/20240814214252_create_comments.rb | 11 +++++ db/schema.rb | 10 +++- test/controllers/comments_controller_test.rb | 7 +++ test/fixtures/comments.yml | 11 +++++ test/models/comment_test.rb | 7 +++ 13 files changed, 78 insertions(+), 52 deletions(-) create mode 100644 app/controllers/comments_controller.rb create mode 100644 app/helpers/comments_helper.rb create mode 100644 app/models/comment.rb create mode 100644 app/views/comments/_comment.html.erb create mode 100644 db/migrate/20240814214252_create_comments.rb create mode 100644 test/controllers/comments_controller_test.rb create mode 100644 test/fixtures/comments.yml create mode 100644 test/models/comment_test.rb diff --git a/app/assets/stylesheets/comments.css b/app/assets/stylesheets/comments.css index bab3257ed..0e0966388 100644 --- a/app/assets/stylesheets/comments.css +++ b/app/assets/stylesheets/comments.css @@ -40,3 +40,9 @@ inline-size: 100%; flex-wrap: wrap; } + +.comment__body { + p:first-child { + margin-block-start: 0; + } +} diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb new file mode 100644 index 000000000..766995515 --- /dev/null +++ b/app/controllers/comments_controller.rb @@ -0,0 +1,2 @@ +class CommentsController < ApplicationController +end diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb new file mode 100644 index 000000000..0ec9ca5f2 --- /dev/null +++ b/app/helpers/comments_helper.rb @@ -0,0 +1,2 @@ +module CommentsHelper +end diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 000000000..cd4b57456 --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,4 @@ +class Comment < ApplicationRecord + belongs_to :splat + belongs_to :creator, class_name: "User", default: -> { Current.user } +end diff --git a/app/models/splat.rb b/app/models/splat.rb index 3273ca19a..9a068bae0 100644 --- a/app/models/splat.rb +++ b/app/models/splat.rb @@ -1,6 +1,7 @@ class Splat < ApplicationRecord has_many :categorizations has_many :categories, through: :categorizations, dependent: :destroy + has_many :comments, dependent: :destroy belongs_to :creator, class_name: "User", default: -> { Current.user } diff --git a/app/models/user.rb b/app/models/user.rb index 0cc02e19b..98787ed1a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,6 +11,10 @@ class User < ApplicationRecord self == Current.user end + def initials + name.scan(/\b\w/).join + end + def deactivate transaction do sessions.delete_all diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb new file mode 100644 index 000000000..f04cd89a4 --- /dev/null +++ b/app/views/comments/_comment.html.erb @@ -0,0 +1,13 @@ +
+
+ <%= comment.creator.initials %> +
+ <%= comment.creator.name %> +
+
+
+ <%= simple_format comment.body %> +
+
+ +
diff --git a/app/views/splats/show.html.erb b/app/views/splats/show.html.erb index e50d2efbe..1566a1951 100644 --- a/app/views/splats/show.html.erb +++ b/app/views/splats/show.html.erb @@ -38,57 +38,7 @@

- -
-
- Added by <%= @splat.creator.name %> on <%= @splat.created_at.strftime("%B %d") %> (<%= time_ago_in_words @splat.created_at %> ago). -
-
- -
- -
-
- JZ -
- Jason Zimdars -
-
-
-

I'll be speaking in Chicago early next month at the ABA convention and they'll be sharing this resource with all State Bar Presidents. I mentioned Writebook in the intro towards the bottom. The platform is awesome!

-
-
- -
- -
-
- JF -
- Jason Fried -
-
-
-

Never mind, I nipped home and tried it on Browser Stack. It's working correctly on Windows with Edge, Chrome & Firefox.

-
-
- -
- -
-
- JF -
- Kevin McConnell -
-
-
-

If this is only happening to one site, and potentially has already resolved itself, then I'll just dig into this on Monday and see if I can find an explanation or a way to reproduce it. Hopefully this isn't a sign of something more common, but so far doesn't sound like it.

-

But if you hear about something similar happening to anyone else, please flag it here and I'll look more urgently.

-
-
- -
+ <%= render @splat.comments %>