Refactor moderation to use a Turbo Stream-backed pagination

This commit is contained in:
Andreas Nedbal 2022-09-04 21:17:10 +02:00 committed by Andreas Nedbal
parent ae607ac840
commit 1375293f31
4 changed files with 16 additions and 10 deletions

View File

@ -11,7 +11,7 @@ class Moderation::ReportsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.js { render layout: false } format.turbo_stream
end end
end end

View File

@ -1,11 +1,9 @@
= turbo_frame_tag "moderation_reports" do
#reports #reports
- @reports.each do |r| - @reports.each do |r|
= render "moderation/moderationbox", report: r = render "moderation/moderationbox", report: r
- unless @reports.count.zero?
= render "shared/cursored_pagination_dummy", more_data_available: @more_data_available, last_id: @reports_last_id, permitted_params: %i[type]
- if @more_data_available - if @more_data_available
.d-flex.justify-content-center.justify-content-sm-start .d-flex.justify-content-center.justify-content-sm-start#paginator
%button.btn.btn-light#load-more-btn{ type: :button, data: { last_id: @reports_last_id } } = button_to moderation_reports_path(last_id: @reports_last_id, type: params[:type]), class: "btn btn-light" do
= t("voc.load") = t("voc.load")

View File

@ -0,0 +1,8 @@
= turbo_stream.append "reports" do
- @reports.each do |r|
= render "moderation/moderationbox", report: r
= turbo_stream.update "paginator" do
- if @more_data_available
= button_to moderation_reports_path(last_id: @reports_last_id, type: params[:type]), class: "btn btn-light" do
= t("voc.load")

View File

@ -24,8 +24,8 @@ Rails.application.routes.draw do
authenticate :user, ->(user) { user.mod? } do authenticate :user, ->(user) { user.mod? } do
post "/moderation/unmask", to: "moderation#toggle_unmask", as: :moderation_toggle_unmask post "/moderation/unmask", to: "moderation#toggle_unmask", as: :moderation_toggle_unmask
get "/moderation/blocks", to: "moderation/anonymous_block#index", as: :mod_anon_block_index get "/moderation/blocks", to: "moderation/anonymous_block#index", as: :mod_anon_block_index
get "/moderation/reports(/:type)", to: "moderation/reports#index", as: :moderation_reports, defaults: { type: "all" }
match "/moderation/inbox/:user", to: "moderation/inbox#index", via: [:get, :post], as: :mod_inbox_index match "/moderation/inbox/:user", to: "moderation/inbox#index", via: [:get, :post], as: :mod_inbox_index
match "/moderation/reports(/:type)", to: "moderation/reports#index", via: [:get, :post], as: :moderation_reports, defaults: { type: "all" }
get "/moderation/questions/:author_identifier", to: "moderation/questions#show", as: :moderation_questions get "/moderation/questions/:author_identifier", to: "moderation/questions#show", as: :moderation_questions
namespace :ajax do namespace :ajax do
post "/mod/destroy_report", to: "moderation#destroy_report", as: :mod_destroy_report post "/mod/destroy_report", to: "moderation#destroy_report", as: :mod_destroy_report