Refactor user questions to use a Turbo Stream-backed pagination
This commit is contained in:
parent
753424f2d2
commit
688a68e769
|
@ -60,7 +60,7 @@ class UserController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js { render layout: false }
|
||||
format.turbo_stream
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#questions
|
||||
- @questions.each do |q|
|
||||
= render 'shared/question', q: q, type: nil
|
||||
= turbo_frame_tag "user_questions" do
|
||||
#questions
|
||||
- @questions.each do |q|
|
||||
= render 'shared/question', q: q, type: nil
|
||||
|
||||
= render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @questions_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: @questions_last_id } }
|
||||
= t("voc.load")
|
||||
- if @more_data_available
|
||||
.d-flex.justify-content-center.justify-content-sm-start#paginator
|
||||
= button_to show_user_questions_path(@user, last_id: @questions_last_id), class: "btn btn-light" do
|
||||
= t("voc.load")
|
||||
|
||||
- provide(:title, questions_title(@user))
|
||||
- parent_layout 'user/profile'
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
$('#questions').append('<% @questions.each do |q|
|
||||
%><%= j render 'shared/question', q: q, type: nil
|
||||
%><% end %>');
|
||||
<% if @more_data_available %>
|
||||
$('#pagination').html('<%= j render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @questions_last_id %>');
|
||||
<% else %>
|
||||
$('#pagination, #load-more-btn').remove();
|
||||
<% end %>
|
|
@ -0,0 +1,8 @@
|
|||
= turbo_stream.append "questions" do
|
||||
- @questions.each do |q|
|
||||
= render 'shared/question', q: q, type: nil
|
||||
|
||||
= turbo_stream.update "paginator" do
|
||||
- if @more_data_available
|
||||
= button_to show_user_questions_path(@user, last_id: @questions_last_id), class: "btn btn-light" do
|
||||
= t("voc.load")
|
|
@ -152,7 +152,7 @@ Rails.application.routes.draw do
|
|||
get "/@:username/followers(/p/:page)", to: "user#followers", as: :show_user_followers, defaults: { page: 1 }
|
||||
get "/@:username/followings(/p/:page)", to: "user#followings", as: :show_user_followings, defaults: { page: 1 }
|
||||
get "/@:username/friends(/p/:page)", to: redirect("/@%{username}/followings/p/%{page}"), defaults: { page: 1 }
|
||||
get "/@:username/questions(/p/:page)", to: "user#questions", as: :show_user_questions, defaults: { page: 1 }
|
||||
match "/@:username/questions(/p/:page)", to: "user#questions", via: [:get, :post], as: :show_user_questions, defaults: { page: 1 }
|
||||
get "/:username(/p/:page)", to: "user#show", as: :user_alt, defaults: { page: 1 }
|
||||
get "/:username/a/:id", to: "answer#show", as: :answer_alt
|
||||
get "/:username/q/:id", to: "question#show", as: :question_alt
|
||||
|
|
Loading…
Reference in New Issue