Refactor mod inbox to use a Turbo Stream-backed pagination

This commit is contained in:
Andreas Nedbal 2022-09-04 23:22:51 +02:00 committed by Andreas Nedbal
parent 8226198f76
commit 8c14fb5423
5 changed files with 18 additions and 20 deletions

View File

@ -12,7 +12,7 @@ class Moderation::InboxController < 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
end end

View File

@ -4,14 +4,12 @@
= render "header", user: @user, hidden: true = render "header", user: @user, hidden: true
.container-lg.container--main .container-lg.container--main
#entries = turbo_frame_tag "moderation_inbox" do
- @inboxes.each do |i| #entries
= render "inbox/entry", i: i - @inboxes.each do |i|
= render "inbox/entry", i: i
= render "shared/cursored_pagination_dummy", more_data_available: @more_data_available, last_id: @inbox_last_id - if @more_data_available
.d-flex.justify-content-center.justify-content-sm-start#paginator
- if @more_data_available = button_to mod_inbox_index_path(@user, last_id: @inbox_last_id), class: "btn btn-light" do
= t("voc.load")
.d-flex.justify-content-center.justify-content-sm-start
%button.btn.btn-light#load-more-btn{ type: :button, data: { last_id: @inbox_last_id } }
= t("voc.load")

View File

@ -1,8 +0,0 @@
$('#entries').append('<% @inboxes.each do |i|
%><%= j render 'inbox/entry', i: i
%><% end %>');
<% if @more_data_available %>
$('#pagination').html('<%= j render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @inbox_last_id %>');
<% else %>
$('#pagination, #load-more-btn').remove();
<% end %>

View File

@ -0,0 +1,8 @@
= turbo_stream.append "entries" do
- @inboxes.each do |i|
= render "inbox/entry", i: i
= turbo_stream.update "paginator" do
- if @more_data_available
= button_to mod_inbox_index_path(@user, last_id: @inbox_last_id), class: "btn btn-light" do
= t("voc.load")

View File

@ -25,7 +25,7 @@ Rails.application.routes.draw 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" } get "/moderation/reports(/:type)", to: "moderation/reports#index", as: :moderation_reports, defaults: { type: "all" }
get "/moderation/inbox/:user", to: "moderation/inbox#index", as: :mod_inbox_index match "/moderation/inbox/:user", to: "moderation/inbox#index", via: [:get, :post], as: :mod_inbox_index
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