2023-02-16 15:35:03 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module PaginatesAnswers
|
|
|
|
def paginate_answers
|
2023-02-19 06:51:19 -08:00
|
|
|
@answers = yield(last_id: params[:last_id])
|
2023-02-16 15:35:03 -08:00
|
|
|
answer_ids = @answers.map(&:id)
|
|
|
|
@answers_last_id = answer_ids.min
|
2023-05-08 11:29:27 -07:00
|
|
|
answer_ids += @pinned_answers.pluck(:id) if @pinned_answers.present?
|
2023-02-19 06:51:19 -08:00
|
|
|
@more_data_available = !yield(last_id: @answers_last_id, size: 1).count.zero?
|
2023-11-07 13:40:37 -08:00
|
|
|
|
|
|
|
return unless user_signed_in?
|
|
|
|
|
|
|
|
@reacted_answer_ids = Reaction.where(user: current_user, parent_type: "Answer", parent_id: answer_ids).pluck(:parent_id)
|
|
|
|
@subscribed_answer_ids = Subscription.where(user: current_user, answer_id: answer_ids).pluck(:answer_id)
|
2023-02-16 15:35:03 -08:00
|
|
|
end
|
|
|
|
end
|