Sort relationship lists by relationship IDs rather than user IDs
This commit is contained in:
parent
486948a54c
commit
e404b61ec1
|
@ -74,9 +74,10 @@ class UserController < ApplicationController
|
|||
def followers
|
||||
@title = 'Followers'
|
||||
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first!
|
||||
@users = @user.cursored_followers(last_id: params[:last_id])
|
||||
@users_last_id = @users.map(&:id).min
|
||||
@more_data_available = !@user.cursored_followers(last_id: @users_last_id, size: 1).count.zero?
|
||||
@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 = :friend
|
||||
|
||||
respond_to do |format|
|
||||
|
@ -89,9 +90,10 @@ class UserController < ApplicationController
|
|||
def followings
|
||||
@title = 'Following'
|
||||
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first!
|
||||
@users = @user.cursored_followings(last_id: params[:last_id])
|
||||
@users_last_id = @users.map(&:id).min
|
||||
@more_data_available = !@user.cursored_followings(last_id: @users_last_id, size: 1).count.zero?
|
||||
@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|
|
||||
|
|
|
@ -5,6 +5,8 @@ module User::RelationshipMethods
|
|||
|
||||
define_cursor_paginator :cursored_followings, :ordered_followings
|
||||
define_cursor_paginator :cursored_followers, :ordered_followers
|
||||
define_cursor_paginator :cursored_following_relationships, :ordered_following_relationships
|
||||
define_cursor_paginator :cursored_follower_relationships, :ordered_follower_relationships
|
||||
|
||||
def ordered_followings
|
||||
followings.reverse_order.includes(:profile)
|
||||
|
@ -13,4 +15,12 @@ module User::RelationshipMethods
|
|||
def ordered_followers
|
||||
followers.reverse_order.includes(:profile)
|
||||
end
|
||||
|
||||
def ordered_following_relationships
|
||||
active_follow_relationships.reverse_order.includes(target: [:profile])
|
||||
end
|
||||
|
||||
def ordered_follower_relationships
|
||||
passive_follow_relationships.reverse_order.includes(source: [:profile])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
.col.pb-3
|
||||
= render 'shared/userbox', user: user, type: @type
|
||||
|
||||
= render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @users_last_id
|
||||
= render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @relationships_last_id
|
||||
|
||||
- if @more_data_available
|
||||
.d-flex.justify-content-center.justify-content-sm-start
|
||||
%button.btn.btn-light#load-more-btn{ type: :button, data: { last_id: @users_last_id } }
|
||||
%button.btn.btn-light#load-more-btn{ type: :button, data: { last_id: @relationships_last_id } }
|
||||
= t 'views.actions.load'
|
||||
|
||||
- provide(:title, user_title(@user, 'friends and followers'))
|
||||
|
|
|
@ -2,7 +2,7 @@ $('#users').append('<% @users.each do |user|
|
|||
%><div class="col pb-3"><%= j render 'shared/userbox', user: user, type: @type
|
||||
%></div><% end %>');
|
||||
<% if @more_data_available %>
|
||||
$('#pagination').html('<%= j render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @users_last_id %>');
|
||||
$('#pagination').html('<%= j render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @relationships_last_id %>');
|
||||
<% else %>
|
||||
$('#pagination, #load-more-btn').remove();
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in New Issue