From e9c397a01350dfc53fd5fced64183596a7d84225 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sat, 28 Jan 2023 19:02:13 +0100 Subject: [PATCH] Replace `@title` and `@type` ivars --- app/controllers/user_controller.rb | 14 ++++---------- app/views/user/show_follow.html.haml | 6 +++--- app/views/user/show_follow.turbo_stream.haml | 4 ++-- config/locales/views.en.yml | 4 ++++ 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index ed054b8d..ad94a2d1 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -17,36 +17,30 @@ class UserController < ApplicationController end def followers - @title = "Followers" @relationships = @user.cursored_follower_relationships(last_id: params[:last_id]) @relationships_last_id = @relationships.map(&:id).min @more_data_available = !@user.cursored_follower_relationships(last_id: @relationships_last_id, size: 1).count.zero? @users = @relationships.map(&:source) - @type = :follower respond_to do |format| - format.html { render "show_follow" } - format.turbo_stream { render "show_follow" } + format.html { render "show_follow", locals: { type: :follower } } + format.turbo_stream { render "show_follow", locals: { type: :follower } } end end def followings - @title = "Following" @relationships = @user.cursored_following_relationships(last_id: params[:last_id]) @relationships_last_id = @relationships.map(&:id).min @more_data_available = !@user.cursored_following_relationships(last_id: @relationships_last_id, size: 1).count.zero? @users = @relationships.map(&:target) - @type = :friend respond_to do |format| - format.html { render "show_follow" } - format.turbo_stream { render "show_follow" } + format.html { render "show_follow", locals: { type: :friend } } + format.turbo_stream { render "show_follow", locals: { type: :friend } } end end def questions - @title = "Questions" - @questions = @user.cursored_questions(author_is_anonymous: false, direct: direct_param, last_id: params[:last_id]) @questions_last_id = @questions.map(&:id).min @more_data_available = !@user.cursored_questions(author_is_anonymous: false, direct: direct_param, last_id: @questions_last_id, size: 1).count.zero? diff --git a/app/views/user/show_follow.html.haml b/app/views/user/show_follow.html.haml index fd341619..bcd981f0 100644 --- a/app/views/user/show_follow.html.haml +++ b/app/views/user/show_follow.html.haml @@ -1,15 +1,15 @@ .row.row-cols-1.row-cols-sm-2.row-cols-md-3#users - @users.each do |user| .col.pb-3 - = render 'shared/userbox', user: user, type: @type + = render 'shared/userbox', user:, type: - if @more_data_available .d-flex.justify-content-center.justify-content-sm-start#paginator - = button_to t("voc.load"), @type == :follower ? show_user_followers_path(@user) : show_user_followings_path(@user), + = button_to t("voc.load"), type == :follower ? show_user_followers_path(@user) : show_user_followings_path(@user), class: "btn btn-light", method: :get, params: { last_id: @relationships_last_id }, form: { data: { turbo_stream: true } } -- provide(:title, user_title(@user, 'friends and followers')) +- provide(:title, t(".title.#{type}", user: @user.profile.safe_name)) - parent_layout 'user/profile' diff --git a/app/views/user/show_follow.turbo_stream.haml b/app/views/user/show_follow.turbo_stream.haml index d36b3b2f..013d730a 100644 --- a/app/views/user/show_follow.turbo_stream.haml +++ b/app/views/user/show_follow.turbo_stream.haml @@ -1,11 +1,11 @@ = turbo_stream.append "users" do - @users.each do |user| .col.pb-3 - = render 'shared/userbox', user: user, type: @type + = render 'shared/userbox', user:, type: = turbo_stream.update "paginator" do - if @more_data_available - = button_to t("voc.load"), @type == :follower ? show_user_followers_path(@user) : show_user_followings_path(@user), + = button_to t("voc.load"), type == :follower ? show_user_followers_path(@user) : show_user_followings_path(@user), class: "btn btn-light", method: :get, params: { last_id: @relationships_last_id }, diff --git a/config/locales/views.en.yml b/config/locales/views.en.yml index 6cc8aca5..295f8aab 100644 --- a/config/locales/views.en.yml +++ b/config/locales/views.en.yml @@ -651,6 +651,10 @@ en: index: title: "Questions from %{author_identifier}" user: + show_follow: + title: + follower: "%{user}'s followers" + friend: "%{user}'s followings" actions: view_inbox: "View inbox" privilege: "Check %{user}'s privileges"