Replace `@title` and `@type` ivars

This commit is contained in:
Karina Kwiatek 2023-01-28 19:02:13 +01:00
parent 6e3bc40c57
commit e9c397a013
4 changed files with 13 additions and 15 deletions

View File

@ -17,36 +17,30 @@ class UserController < ApplicationController
end end
def followers def followers
@title = "Followers"
@relationships = @user.cursored_follower_relationships(last_id: params[:last_id]) @relationships = @user.cursored_follower_relationships(last_id: params[:last_id])
@relationships_last_id = @relationships.map(&:id).min @relationships_last_id = @relationships.map(&:id).min
@more_data_available = !@user.cursored_follower_relationships(last_id: @relationships_last_id, size: 1).count.zero? @more_data_available = !@user.cursored_follower_relationships(last_id: @relationships_last_id, size: 1).count.zero?
@users = @relationships.map(&:source) @users = @relationships.map(&:source)
@type = :follower
respond_to do |format| respond_to do |format|
format.html { render "show_follow" } format.html { render "show_follow", locals: { type: :follower } }
format.turbo_stream { render "show_follow" } format.turbo_stream { render "show_follow", locals: { type: :follower } }
end end
end end
def followings def followings
@title = "Following"
@relationships = @user.cursored_following_relationships(last_id: params[:last_id]) @relationships = @user.cursored_following_relationships(last_id: params[:last_id])
@relationships_last_id = @relationships.map(&:id).min @relationships_last_id = @relationships.map(&:id).min
@more_data_available = !@user.cursored_following_relationships(last_id: @relationships_last_id, size: 1).count.zero? @more_data_available = !@user.cursored_following_relationships(last_id: @relationships_last_id, size: 1).count.zero?
@users = @relationships.map(&:target) @users = @relationships.map(&:target)
@type = :friend
respond_to do |format| respond_to do |format|
format.html { render "show_follow" } format.html { render "show_follow", locals: { type: :friend } }
format.turbo_stream { render "show_follow" } format.turbo_stream { render "show_follow", locals: { type: :friend } }
end end
end end
def questions def questions
@title = "Questions"
@questions = @user.cursored_questions(author_is_anonymous: false, direct: direct_param, last_id: params[:last_id]) @questions = @user.cursored_questions(author_is_anonymous: false, direct: direct_param, last_id: params[:last_id])
@questions_last_id = @questions.map(&:id).min @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? @more_data_available = !@user.cursored_questions(author_is_anonymous: false, direct: direct_param, last_id: @questions_last_id, size: 1).count.zero?

View File

@ -1,15 +1,15 @@
.row.row-cols-1.row-cols-sm-2.row-cols-md-3#users .row.row-cols-1.row-cols-sm-2.row-cols-md-3#users
- @users.each do |user| - @users.each do |user|
.col.pb-3 .col.pb-3
= render 'shared/userbox', user: user, type: @type = render 'shared/userbox', user:, type:
- if @more_data_available - if @more_data_available
.d-flex.justify-content-center.justify-content-sm-start#paginator .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", class: "btn btn-light",
method: :get, method: :get,
params: { last_id: @relationships_last_id }, params: { last_id: @relationships_last_id },
form: { data: { turbo_stream: true } } 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' - parent_layout 'user/profile'

View File

@ -1,11 +1,11 @@
= turbo_stream.append "users" do = turbo_stream.append "users" do
- @users.each do |user| - @users.each do |user|
.col.pb-3 .col.pb-3
= render 'shared/userbox', user: user, type: @type = render 'shared/userbox', user:, type:
= turbo_stream.update "paginator" do = turbo_stream.update "paginator" do
- if @more_data_available - 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", class: "btn btn-light",
method: :get, method: :get,
params: { last_id: @relationships_last_id }, params: { last_id: @relationships_last_id },

View File

@ -651,6 +651,10 @@ en:
index: index:
title: "Questions from %{author_identifier}" title: "Questions from %{author_identifier}"
user: user:
show_follow:
title:
follower: "%{user}'s followers"
friend: "%{user}'s followings"
actions: actions:
view_inbox: "View inbox" view_inbox: "View inbox"
privilege: "Check %{user}'s privileges" privilege: "Check %{user}'s privileges"