From 21e6238dfe4c6cb320f5d9a193175800a71e6cb3 Mon Sep 17 00:00:00 2001 From: Paul McKissock Date: Tue, 2 Jul 2024 16:37:20 -0400 Subject: [PATCH] Changed article show and render_comment_tree so that it fits with new application.html.erb. --- app/assets/stylesheets/application.css | 5 ++ app/controllers/comments_controller.rb | 2 +- app/helpers/comments_helper.rb | 26 ++++----- app/views/articles/show.html.erb | 75 +++++++++++++++++++------- app/views/layouts/application.html.erb | 4 +- 5 files changed, 78 insertions(+), 34 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 0e97212..9850b8c 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -70,6 +70,11 @@ cursor: pointer; text-decoration: underline; } + + .comment { + max-width: 1215px; + overflow-wrap: anywhere; +} a:link { color:#000000; text-decoration:none; } diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 52aaf5b..5fbcbae 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,5 +1,5 @@ class CommentsController < ApplicationController - before_action :authorized, only: [:create] + before_action :authorized, only: [:create, :upvote, :downvote] helper_method :comment def show diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 9e9ad3d..8428c58 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -2,20 +2,20 @@ module CommentsHelper def render_comment_tree(comment) content_tag :li do concat content_tag(:p, comment.text) - concat content_tag(:div, style: "display: flex; align-items: center;") { - safe_concat "Posted by " - safe_concat link_to(comment.user.name, comment.user) - safe_concat " on #{comment.created_at.strftime("%B %d, %Y at %I:%M %p")}" - safe_concat " - Score: " - safe_concat content_tag(:span, comment.score, id: "score-Comment-#{comment.id}") - - safe_concat button_to("Upvote", upvote_article_comment_path(comment.article, comment), method: :post, class: "btn btn-sm upvote-button", data: {votable_type: "Comment", votable_id: comment.id, article_id: comment.article.id}) - safe_concat button_to("Downvote", downvote_article_comment_path(comment.article, comment), method: :post, class: "btn btn-sm downvote-button", data: {votable_type: "Comment", votable_id: comment.id, article_id: comment.article.id}) - } - concat content_tag(:p) { - safe_concat link_to("reply", article_comment_path(comment.article, comment)) - } + concat content_tag(:div, class: "subtext", style: "display: flex; align-items: center;") { + safe_concat button_to("Upvote", upvote_article_comment_path(comment.article, comment), method: :post, class: "btn btn-sm upvote-button", data: {votable_type: "Comment", votable_id: comment.id, article_id: comment.article.id}) + safe_concat button_to("Downvote", downvote_article_comment_path(comment.article, comment), method: :post, class: "btn btn-sm downvote-button", data: {votable_type: "Comment", votable_id: comment.id, article_id: comment.article.id}) + safe_concat content_tag(:span, "#{comment.score} points", id: "score-Comment-#{comment.id}", class: "score") + concat raw(" ") + safe_concat "by" + concat raw(" ") + safe_concat link_to(comment.user.name, comment.user) + concat raw(" ") + safe_concat "on #{comment.created_at.strftime("%B %d, %Y at %I:%M %p")}" + safe_concat " | " + safe_concat link_to(" reply", article_comment_path(comment.article, comment)) + } if comment.replies.any? concat(content_tag(:ul) do comment.replies.each do |reply| diff --git a/app/views/articles/show.html.erb b/app/views/articles/show.html.erb index 5d8e308..42812f3 100644 --- a/app/views/articles/show.html.erb +++ b/app/views/articles/show.html.erb @@ -1,18 +1,57 @@ -

<%= @article.title %>

-

<%= link_to @article.link, @article.link %>

- -<%= form_with(model: [@article, @comment], local: true) do |form| %> -
- <%= form.text_area :text %> -
-
- <%= form.submit %> -
-<% end %> - -

Comments

- + + + + + + + + + + + + + + + + + + + + + + +
+ 1. + + <%= link_to @article.title, @article.link, target: "_blank" %> +
+ <%= @article.score %> points + by <%= link_to @article.user.name, user_path(@article.user) %> + <%= time_ago_in_words(@article.created_at) %> ago +
+ <%= form_with(model: [@article, @comment], local: true) do |form| %> +
+ <%= form.text_area :text %> +
+
+ <%= form.submit %> +
+ <% end %> +
+
    + <% @comments.each do |comment| %> + <%= render_comment_tree(comment) %> + <% end %> +
+
+ + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 45fb4a9..f600a84 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,14 +1,14 @@ - <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> Haxxor News + + <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag 'application', media: 'all' %> <%= javascript_include_tag 'application' %> -