Appease the dog overlords

This commit is contained in:
Karina Kwiatek 2023-02-17 00:35:03 +01:00
parent 2604e6b240
commit 7aed99d187
12 changed files with 33 additions and 21 deletions

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
module PaginatesAnswers
def paginate_answers
answer_ids = @answers.map(&:id)
answer_ids += @pinned_answers.pluck(:id) if @pinned_answers.present?
@answers_last_id = answer_ids.min
@more_data_available = !@user.cursored_answers(last_id: @answers_last_id, size: 1).count.zero?
Subscription.where(user: current_user, answer_id: answer_ids + @pinned_answers.pluck(:id)).pluck(:answer_id) if user_signed_in?
end
end

View File

@ -1,6 +1,8 @@
# frozen_string_literal: true
class QuestionController < ApplicationController
include PaginatesAnswers
def show
@question = Question.find(params[:id])
@answers = @question.cursored_answers(last_id: params[:last_id], current_user:)
@ -10,8 +12,8 @@ class QuestionController < ApplicationController
@subscribed = Subscription.where(user: current_user, answer_id: answer_ids).pluck(:answer_id) if user_signed_in?
respond_to do |format|
format.html
format.turbo_stream { render layout: false, status: :see_other }
format.html { render locals: { subscribed_answer_ids: } }
format.turbo_stream { render layout: false, status: :see_other, locals: { subscribed_answer_ids: } }
end
end
end

View File

@ -35,11 +35,11 @@ class TimelineController < ApplicationController
timeline_ids = @timeline.map(&:id)
@timeline_last_id = timeline_ids.min
@more_data_available = !yield(last_id: @timeline_last_id, size: 1).count.zero?
@subscribed = Subscription.where(user: current_user, answer_id: timeline_ids).pluck(:answer_id) if user_signed_in?
subscribed_answer_ids = Subscription.where(user: current_user, answer_id: timeline_ids).pluck(:answer_id) if user_signed_in?
respond_to do |format|
format.html { render "timeline/timeline" }
format.turbo_stream { render "timeline/timeline", layout: false, status: :see_other }
format.html { render "timeline/timeline", locals: { subscribed_answer_ids: } }
format.turbo_stream { render "timeline/timeline", layout: false, status: :see_other, locals: { subscribed_answer_ids: } }
end
end
end

View File

@ -1,21 +1,20 @@
# frozen_string_literal: true
class UserController < ApplicationController
include PaginatesAnswers
before_action :set_user
before_action :hidden_social_graph_redirect, only: %i[followers followings]
after_action :mark_notification_as_read, only: %i[show]
def show
@answers = @user.cursored_answers(last_id: params[:last_id])
answer_ids = @answers.map(&:id)
@pinned_answers = @user.answers.pinned.order(pinned_at: :desc).limit(10)
@answers_last_id = answer_ids.min
@more_data_available = !@user.cursored_answers(last_id: @answers_last_id, size: 1).count.zero?
@subscribed = Subscription.where(user: current_user, answer_id: answer_ids).pluck(:answer_id) if user_signed_in?
subscribed_answer_ids = paginate_answers
respond_to do |format|
format.html
format.turbo_stream
format.html { render locals: { subscribed_answer_ids: } }
format.turbo_stream { render layout: false, locals: { subscribed_answer_ids: } }
end
end

View File

@ -1,5 +1,5 @@
.dropdown-menu.dropdown-menu-end{ role: :menu }
- if @subscribed&.include?(answer.id)
- if subscribed_answer_ids&.include?(answer.id)
-# fun joke should subscribe?
%a.dropdown-item{ href: "#", data: { a_id: answer.id, action: "ab-submarine", torpedo: "no" } }
%i.fa.fa-fw.fa-anchor

View File

@ -13,4 +13,4 @@
.btn-group
%button.btn.btn-default.btn-sm.dropdown-toggle{ data: { bs_toggle: :dropdown }, aria: { expanded: false } }
%span.caret
= render "actions/answer", answer: a
= render "actions/answer", answer: a, subscribed_answer_ids:

View File

@ -21,7 +21,7 @@
.answerbox__answer-date
= link_to(raw(t("time.distance_ago", time: time_tooltip(a))), answer_path(a.user.screen_name, a.id), data: { selection_hotkey: "l" })
.col-md-6.d-flex.d-md-block.answerbox__actions
= render "answerbox/actions", a: a, display_all: display_all
= render "answerbox/actions", a:, display_all:, subscribed_answer_ids:
- else
.row
.col-md-6.text-start.text-muted
@ -33,7 +33,7 @@
%i.fa.fa-thumbtack
= t(".pinned")
.col-md-6.d-md-flex.answerbox__actions
= render "answerbox/actions", a: a, display_all: display_all
= render "answerbox/actions", a:, display_all:, subscribed_answer_ids:
.card-footer{ id: "ab-comments-section-#{a.id}", class: display_all.nil? ? "d-none" : nil }
%div{ id: "ab-smiles-#{a.id}" }= render "answerbox/smiles", a: a
%div{ id: "ab-comments-#{a.id}" }= render "answerbox/comments", a: a

View File

@ -6,7 +6,7 @@
%button.d-none{ data: { hotkey: "j", action: "navigation#down" } }
%button.d-none{ data: { hotkey: "k", action: "navigation#up" } }
- @answers.each do |a|
= render "answerbox", a: a, show_question: false
= render "answerbox", a:, show_question: false, subscribed_answer_ids:
- if @more_data_available
.d-flex.justify-content-center.justify-content-sm-start#paginator

View File

@ -1,6 +1,6 @@
= turbo_stream.append "answers" do
- @answers.each do |a|
= render "answerbox", a: a, show_question: false
= render "answerbox", a:, show_question: false, subscribed_answer_ids:
= turbo_stream.update "paginator" do
- if @more_data_available

View File

@ -2,7 +2,7 @@
%button.d-none{ data: { hotkey: "j", action: "navigation#down" } }
%button.d-none{ data: { hotkey: "k", action: "navigation#up" } }
- @timeline.each do |answer|
= render "answerbox", a: answer
= render "answerbox", a: answer, subscribed_answer_ids:
- if @more_data_available
.d-flex.justify-content-center#paginator

View File

@ -4,11 +4,11 @@
%button.d-none{ data: { hotkey: "k", action: "navigation#up" } }
#pinned-answers
- @pinned_answers.each do |a|
= render "answerbox", a:
= render "answerbox", a:, subscribed_answer_ids:
#answers
- @answers.each do |a|
= render "answerbox", a:
= render "answerbox", a:, subscribed_answer_ids:
- if @more_data_available
.d-flex.justify-content-center.justify-content-sm-start#paginator

View File

@ -1,6 +1,6 @@
= turbo_stream.append "answers" do
- @answers.each do |a|
= render 'answerbox', a: a
= render "answerbox", a:, subscribed_answer_ids:
= turbo_stream.update "paginator" do
- if @more_data_available