Skip to content

A platform for community discussion. Free, open, simple.

FIX: going from /categories to /latest on mobile might break infinite scrolling

Régis Hanol12bab6516796
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index 0489bed9aa9..e709d0e865c 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -48,11 +48,13 @@ class CategoriesController < ApplicationController
if style == "categories_and_latest_topics".freeze
@topic_list = TopicQuery.new(current_user, topic_options).list_latest
+ @topic_list.more_topics_url = url_for(public_send("latest_path"))
elsif style == "categories_and_top_topics".freeze
@topic_list = TopicQuery.new(nil, topic_options).list_top_for(SiteSetting.top_page_default_timeframe.to_sym)
+ @topic_list.more_topics_url = url_for(public_send("top_path"))
end
- if @topic_list.present?
+ if @topic_list.present? && @topic_list.topics.present?
store_preloaded(
@topic_list.preload_key,
MultiJson.dump(TopicListSerializer.new(@topic_list, scope: guardian))
diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index 28fb8a05620..cf1f09cf208 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -401,7 +401,7 @@ class TopicQuery
end
list = TopicList.new(filter, @user, topics, options.merge(@options))
- list.per_page = per_page_setting
+ list.per_page = options[:per_page] || per_page_setting
list
end
diff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rb
index 32a6677d83e..ddcd111f517 100644
--- a/spec/requests/categories_controller_spec.rb
+++ b/spec/requests/categories_controller_spec.rb
@@ -26,6 +26,13 @@ describe CategoriesController do
expect(html.css('body.crawler')).to be_present
expect(html.css("a[href=\"/forum/c/#{category.slug}\"]")).to be_present
end
+
+ it "properly preloads topic list" do
+ SiteSetting.categories_topics = 5
+ SiteSetting.categories_topics.times { Fabricate(:topic) }
+ get "/categories"
+ expect(response.body).to include(%{"more_topics_url":"/latest"})
+ end
end
context 'extensibility event' do