Refactor questions to use a Turbo Stream-backed pagination
This commit is contained in:
parent
b595910564
commit
6ae03dbd7f
|
@ -7,7 +7,7 @@ class QuestionController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js { render layout: false }
|
||||
format.turbo_stream { render layout: false, status: :see_other }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,11 +6,9 @@
|
|||
- @answers.each do |a|
|
||||
= render "answerbox", a: a, show_question: false
|
||||
|
||||
= render "shared/cursored_pagination_dummy", more_data_available: @more_data_available, last_id: @answers_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: @answers_last_id } }
|
||||
.d-flex.justify-content-center.justify-content-sm-start#paginator
|
||||
= button_to question_path(@question.user.screen_name, @question.id, last_id: @answers_last_id), class: "btn btn-light" do
|
||||
= t("voc.load")
|
||||
|
||||
- if user_signed_in? && !current_user.answered?(@question) && current_user != @question.user && @question.user&.privacy_allow_stranger_answers
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
$('#answers').append('<% @answers.each do |answer|
|
||||
%><%= j render 'answerbox', a: answer, show_question: false
|
||||
%><% end %>');
|
||||
<% if @more_data_available %>
|
||||
$('#pagination').html('<%= j render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @answers_last_id %>');
|
||||
<% else %>
|
||||
$('#pagination, #load-more-btn').remove();
|
||||
<% end %>
|
|
@ -0,0 +1,8 @@
|
|||
= turbo_stream.append "answers" do
|
||||
- @answers.each do |a|
|
||||
= render "answerbox", a: a, show_question: false
|
||||
|
||||
= turbo_stream.update "paginator" do
|
||||
- if @more_data_available
|
||||
= button_to question_path(@question.user.screen_name, @question.id, last_id: @answers_last_id), class: "btn btn-light" do
|
||||
= t("voc.load")
|
|
@ -148,7 +148,7 @@ Rails.application.routes.draw do
|
|||
match "/user/:username(/p/:page)", to: "user#show", via: [:get, :post], defaults: { page: 1 }
|
||||
match "/@:username(/p/:page)", to: "user#show", via: [:get, :post], as: :user, defaults: { page: 1 }
|
||||
get "/@:username/a/:id", to: "answer#show", via: "get", as: :answer
|
||||
get "/@:username/q/:id", to: "question#show", via: "get", as: :question
|
||||
match "/@:username/q/:id", to: "question#show", via: [:get, :post], as: :question
|
||||
match "/@:username/followers(/p/:page)", to: "user#followers", via: [:get, :post], as: :show_user_followers, defaults: { page: 1 }
|
||||
match "/@:username/followings(/p/:page)", to: "user#followings", via: [:get, :post], as: :show_user_followings, defaults: { page: 1 }
|
||||
match "/@:username/friends(/p/:page)", to: redirect("/@%{username}/followings/p/%{page}"), via: [:get, :post], defaults: { page: 1 }
|
||||
|
|
Loading…
Reference in New Issue