diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 6d1b23579..650bcba10 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -318,7 +318,7 @@ class StoriesController < ApplicationController end def assign_user_comments - comment_count = params[:view] == "comments" ? 250 : 8 + comment_count = helpers.comment_count(params[:view]) @comments = if @user.comments_count.positive? @user.comments.where(deleted: false) .order(created_at: :desc).includes(:commentable).limit(comment_count) diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 8db8c9852..39663a03f 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -1,4 +1,7 @@ module CommentsHelper + MAX_COMMENTS_TO_RENDER = 250 + MIN_COMMENTS_TO_RENDER = 8 + def comment_class(comment, is_view_root: false) if comment.root? || is_view_root "root" @@ -31,6 +34,22 @@ module CommentsHelper comment.hidden_by_commentable_user && comment != root_comment end + def high_number_of_comments?(comments_number) + comments_number > MAX_COMMENTS_TO_RENDER + end + + def view_all_comments?(comments_number) + comments_number > MIN_COMMENTS_TO_RENDER + end + + def number_of_comments_to_render + MAX_COMMENTS_TO_RENDER + end + + def comment_count(view) + view == "comments" ? MAX_COMMENTS_TO_RENDER : MIN_COMMENTS_TO_RENDER + end + def like_button_text(comment) case comment.public_reactions_count when 0 diff --git a/app/views/users/_comments_section.html.erb b/app/views/users/_comments_section.html.erb index 3a788edab..5ad5a6070 100644 --- a/app/views/users/_comments_section.html.erb +++ b/app/views/users/_comments_section.html.erb @@ -4,8 +4,8 @@ <% if params[:view] == "comments" %>