diff --git a/app/controllers/question_controller.rb b/app/controllers/question_controller.rb index 7854d8df..f8a3ffa1 100644 --- a/app/controllers/question_controller.rb +++ b/app/controllers/question_controller.rb @@ -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 diff --git a/app/views/question/show.haml b/app/views/question/show.haml index 6ece7de6..746fb6c9 100644 --- a/app/views/question/show.haml +++ b/app/views/question/show.haml @@ -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 diff --git a/app/views/question/show.js.erb b/app/views/question/show.js.erb deleted file mode 100644 index fbbf582f..00000000 --- a/app/views/question/show.js.erb +++ /dev/null @@ -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 %> diff --git a/app/views/question/show.turbo_stream.haml b/app/views/question/show.turbo_stream.haml new file mode 100644 index 00000000..98f9d803 --- /dev/null +++ b/app/views/question/show.turbo_stream.haml @@ -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") diff --git a/config/routes.rb b/config/routes.rb index 075c3b83..b42e0cdf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 }