A platform for community discussion. Free, open, simple.
FIX: Failed to load the next page in discourse-reactions (#36451)
small-lovely-cat0a9ecec7fbd9
diff --git a/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rb b/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rbindex 3ccbb62bf3e..cb948f69cb0 100644--- a/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rb+++ b/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rb@@ -2,6 +2,7 @@class DiscourseReactions::CustomReactionsController < ApplicationControllerMAX_USERS_COUNT = 26+ PAGE_SIZE = 20requires_plugin DiscourseReactions::PLUGIN_NAME@@ -79,7 +80,7 @@ class DiscourseReactions::CustomReactionsController < ApplicationController)end- reaction_users = reaction_users.order(created_at: :desc).limit(20)+ reaction_users = reaction_users.order(created_at: :desc).limit(PAGE_SIZE)render_serialized(reaction_users.to_a, UserReactionSerializer)end@@ -120,7 +121,7 @@ class DiscourseReactions::CustomReactionsController < ApplicationControllerreaction_users.joins(:user).where(users: { username: params[:acting_username] })end- reaction_users = reaction_users.order(created_at: :desc).limit(20).to_a+ reaction_users = reaction_users.order(created_at: :desc).limit(PAGE_SIZE).to_aif params[:include_likes]# We do not want to include likes that also count as@@ -140,7 +141,7 @@ class DiscourseReactions::CustomReactionsController < ApplicationControllerSQL.where("discourse_reactions_reaction_users.id IS NULL").order(created_at: :desc)- .limit(20)+ .limit(PAGE_SIZE)if params[:before_like_id]likes = likes.where("post_actions.id < ?", params[:before_like_id].to_i)@@ -154,7 +155,7 @@ class DiscourseReactions::CustomReactionsController < ApplicationControllerreaction_users = reaction_users.sort { |a, b| b.created_at <=> a.created_at }end- render_serialized reaction_users.first(20), UserReactionSerializer+ render_serialized reaction_users.first(PAGE_SIZE), UserReactionSerializerenddef post_reactions_usersdiff --git a/plugins/discourse-reactions/assets/javascripts/discourse/controllers/user-activity/reactions.js b/plugins/discourse-reactions/assets/javascripts/discourse/controllers/user-activity/reactions.jsindex ea177c686b5..5791d7748eb 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/controllers/user-activity/reactions.js+++ b/plugins/discourse-reactions/assets/javascripts/discourse/controllers/user-activity/reactions.js@@ -15,7 +15,7 @@ export default class UserActivityReactions extends Controller {@tracked beforeReactionUserId = null;#getLastIdFrom(array) {- return array.length ? array[array.length - 1].id : null;+ return array.length ? array[array.length - 1].reaction_user_id : null;}#updateBeforeIds(reactionUsers) {diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/models/discourse-reactions-custom-reaction.js b/plugins/discourse-reactions/assets/javascripts/discourse/models/discourse-reactions-custom-reaction.jsindex 3d5236c7fa0..8db32fae611 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/models/discourse-reactions-custom-reaction.js+++ b/plugins/discourse-reactions/assets/javascripts/discourse/models/discourse-reactions-custom-reaction.js@@ -6,6 +6,8 @@ import RestModel from "discourse/models/rest";import Topic from "discourse/models/topic";import User from "discourse/models/user";+export const PAGE_SIZE = 20;+export default class CustomReaction extends RestModel {static toggle(post, reactionId, appEvents) {return ajax(@@ -23,6 +25,8 @@ export default class CustomReaction extends RestModel {return {// Original reaction data...reaction,+ // Preserve reaction_user.id for pagination+ reaction_user_id: reaction.id,// Flatten post fields to top level for PostListItemid: reaction.post.id,user_id: reaction.post.user_id,diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/routes/user-activity/reactions.js b/plugins/discourse-reactions/assets/javascripts/discourse/routes/user-activity/reactions.jsindex 82325ea5f13..814d0f3d8fb 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/routes/user-activity/reactions.js+++ b/plugins/discourse-reactions/assets/javascripts/discourse/routes/user-activity/reactions.js@@ -1,6 +1,8 @@import { TrackedArray } from "@ember-compat/tracked-built-ins";import DiscourseRoute from "discourse/routes/discourse";-import CustomReaction from "../../models/discourse-reactions-custom-reaction";+import CustomReaction, {+ PAGE_SIZE,+} from "../../models/discourse-reactions-custom-reaction";export default class UserActivityReactions extends DiscourseRoute {async model() {@@ -15,7 +17,7 @@ export default class UserActivityReactions extends DiscourseRoute {}setupController(controller, model) {- let loadedAll = model.length < 20;+ let loadedAll = model.length < PAGE_SIZE;this.controllerFor("user-activity.reactions").setProperties({model,canLoadMore: !loadedAll,diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/routes/user-notifications/reactions-received.js b/plugins/discourse-reactions/assets/javascripts/discourse/routes/user-notifications/reactions-received.jsindex bf7bd254fc5..3f73d97555f 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/routes/user-notifications/reactions-received.js+++ b/plugins/discourse-reactions/assets/javascripts/discourse/routes/user-notifications/reactions-received.js@@ -1,6 +1,8 @@import { TrackedArray } from "@ember-compat/tracked-built-ins";import DiscourseRoute from "discourse/routes/discourse";-import CustomReaction from "../../models/discourse-reactions-custom-reaction";+import CustomReaction, {+ PAGE_SIZE,+} from "../../models/discourse-reactions-custom-reaction";export default class UserNotificationsReactionsReceived extends DiscourseRoute {templateName = "user-activity.reactions";@@ -27,7 +29,7 @@ export default class UserNotificationsReactionsReceived extends DiscourseRoute {}setupController(controller, model) {- const loadedAll = model.length < 20;+ const loadedAll = model.length < PAGE_SIZE;this.controllerFor("user-activity.reactions").setProperties({model,diff --git a/plugins/discourse-reactions/spec/system/reactions_activity_spec.rb b/plugins/discourse-reactions/spec/system/reactions_activity_spec.rbindex 4c018260934..843972b55b5 100644--- a/plugins/discourse-reactions/spec/system/reactions_activity_spec.rb+++ b/plugins/discourse-reactions/spec/system/reactions_activity_spec.rb@@ -9,6 +9,35 @@ describe "Reactions | Activity", type: :system dosign_in(current_user)end+ describe "reactions received pagination" do+ fab!(:reactor, :user)++ it "loads more unique reactions when scrolling" do+ # Create more posts than fit on one page to trigger pagination+ page_size = DiscourseReactions::CustomReactionsController::PAGE_SIZE+ posts = Fabricate.times(page_size + 5, :post, user: current_user)+ posts.each do |post|+ DiscourseReactions::ReactionManager.new(+ reaction_value: "clap",+ user: reactor,+ post: post,+ ).toggle!+ end++ visit("/u/#{current_user.username}/notifications/reactions-received")++ initial_items = page.all(".user-stream-item")+ expect(initial_items.count).to be < posts.count++ page.execute_script("window.scrollTo(0, document.body.scrollHeight)")++ expect(page).to have_css(".user-stream-item", count: posts.count, wait: 5)++ post_ids = page.all(".user-stream-item [data-post-id]").map { |el| el["data-post-id"] }+ expect(post_ids.uniq.count).to eq(posts.count)+ end+ end+context "when current user reacts to a post" dofab!(:post_1, :post)before do