mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -05:00
FIX: Category latest pages were not preloading properly, causing weird
refreshes when clicking the home logo.
This commit is contained in:
parent
8a88e71b3c
commit
1f26a79899
5 changed files with 30 additions and 11 deletions
|
@ -186,7 +186,7 @@ class ListController < ApplicationController
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
@list = list
|
@list = list
|
||||||
store_preloaded("topic_list_#{list.filter}", MultiJson.dump(TopicListSerializer.new(list, scope: guardian)))
|
store_preloaded(list.preload_key, MultiJson.dump(TopicListSerializer.new(list, scope: guardian)))
|
||||||
render 'list'
|
render 'list'
|
||||||
end
|
end
|
||||||
format.json do
|
format.json do
|
||||||
|
|
|
@ -11,10 +11,20 @@ class TopicList
|
||||||
:filter,
|
:filter,
|
||||||
:for_period
|
:for_period
|
||||||
|
|
||||||
def initialize(filter, current_user, topics)
|
def initialize(filter, current_user, topics, opts=nil)
|
||||||
@filter = filter
|
@filter = filter
|
||||||
@current_user = current_user
|
@current_user = current_user
|
||||||
@topics_input = topics
|
@topics_input = topics
|
||||||
|
@opts = opts || {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def preload_key
|
||||||
|
if @opts[:category]
|
||||||
|
c = Category.find(@opts[:category_id])
|
||||||
|
"topic_list_#{c.url.sub(/^\//, '')}/l/#{@filter}"
|
||||||
|
else
|
||||||
|
"topic_list_#{@filter}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Lazy initialization
|
# Lazy initialization
|
||||||
|
|
|
@ -65,7 +65,7 @@ class TopicQuery
|
||||||
|
|
||||||
# The latest view of topics
|
# The latest view of topics
|
||||||
def list_latest
|
def list_latest
|
||||||
TopicList.new(:latest, @user, latest_results)
|
create_list(:latest, {}, latest_results)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The starred topics
|
# The starred topics
|
||||||
|
@ -80,11 +80,11 @@ class TopicQuery
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_new
|
def list_new
|
||||||
TopicList.new(:new, @user, new_results)
|
create_list(:new, {}, new_results)
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_unread
|
def list_unread
|
||||||
TopicList.new(:new, @user, unread_results)
|
create_list(:new, {}, unread_results)
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_posted
|
def list_posted
|
||||||
|
@ -111,19 +111,19 @@ class TopicQuery
|
||||||
|
|
||||||
def list_private_messages(user)
|
def list_private_messages(user)
|
||||||
list = private_messages_for(user)
|
list = private_messages_for(user)
|
||||||
TopicList.new(:private_messages, user, list)
|
create_list(:private_messages, {}, list)
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_private_messages_sent(user)
|
def list_private_messages_sent(user)
|
||||||
list = private_messages_for(user)
|
list = private_messages_for(user)
|
||||||
list = list.where(user_id: user.id)
|
list = list.where(user_id: user.id)
|
||||||
TopicList.new(:private_messages, user, list)
|
create_list(:private_messages, {}, list)
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_private_messages_unread(user)
|
def list_private_messages_unread(user)
|
||||||
list = private_messages_for(user)
|
list = private_messages_for(user)
|
||||||
list = list.where("tu.last_read_post_number IS NULL OR tu.last_read_post_number < topics.highest_post_number")
|
list = list.where("tu.last_read_post_number IS NULL OR tu.last_read_post_number < topics.highest_post_number")
|
||||||
TopicList.new(:private_messages, user, list)
|
create_list(:private_messages, {}, list)
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_category(category)
|
def list_category(category)
|
||||||
|
@ -158,7 +158,7 @@ class TopicQuery
|
||||||
def create_list(filter, options={}, topics = nil)
|
def create_list(filter, options={}, topics = nil)
|
||||||
topics ||= default_results(options)
|
topics ||= default_results(options)
|
||||||
topics = yield(topics) if block_given?
|
topics = yield(topics) if block_given?
|
||||||
TopicList.new(filter, @user, topics)
|
TopicList.new(filter, @user, topics, options.merge(@options))
|
||||||
end
|
end
|
||||||
|
|
||||||
def private_messages_for(user)
|
def private_messages_for(user)
|
||||||
|
@ -241,6 +241,7 @@ class TopicQuery
|
||||||
end
|
end
|
||||||
|
|
||||||
category_id = get_category_id(options[:category])
|
category_id = get_category_id(options[:category])
|
||||||
|
@options[:category_id] = category_id
|
||||||
if category_id
|
if category_id
|
||||||
if options[:no_subcategories]
|
if options[:no_subcategories]
|
||||||
result = result.where('categories.id = ?', category_id)
|
result = result.where('categories.id = ?', category_id)
|
||||||
|
|
|
@ -43,7 +43,7 @@ describe TopicQuery do
|
||||||
context 'category filter' do
|
context 'category filter' do
|
||||||
let(:category) { Fabricate(:category) }
|
let(:category) { Fabricate(:category) }
|
||||||
|
|
||||||
let(:diff_category) { Fabricate(:category) }
|
let(:diff_category) { Fabricate(:diff_category) }
|
||||||
|
|
||||||
it "returns topics in the category when we filter to it" do
|
it "returns topics in the category when we filter to it" do
|
||||||
TopicQuery.new(moderator).list_latest.topics.size.should == 0
|
TopicQuery.new(moderator).list_latest.topics.size.should == 0
|
||||||
|
@ -51,7 +51,10 @@ describe TopicQuery do
|
||||||
# Filter by slug
|
# Filter by slug
|
||||||
TopicQuery.new(moderator, category: category.slug).list_latest.topics.size.should == 1
|
TopicQuery.new(moderator, category: category.slug).list_latest.topics.size.should == 1
|
||||||
TopicQuery.new(moderator, category: "#{category.id}-category").list_latest.topics.size.should == 1
|
TopicQuery.new(moderator, category: "#{category.id}-category").list_latest.topics.size.should == 1
|
||||||
TopicQuery.new(moderator, category: diff_category.slug).list_latest.topics.size.should == 1
|
|
||||||
|
list = TopicQuery.new(moderator, category: diff_category.slug).list_latest
|
||||||
|
list.topics.size.should == 1
|
||||||
|
list.preload_key.should == "topic_list_category/different-category/l/latest"
|
||||||
|
|
||||||
# Defaults to no category filter when slug does not exist
|
# Defaults to no category filter when slug does not exist
|
||||||
TopicQuery.new(moderator, category: 'made up slug').list_latest.topics.size.should == 2
|
TopicQuery.new(moderator, category: 'made up slug').list_latest.topics.size.should == 2
|
||||||
|
|
|
@ -2,3 +2,8 @@ Fabricator(:category) do
|
||||||
name { sequence(:name) { |n| "Amazing Category #{n}" } }
|
name { sequence(:name) { |n| "Amazing Category #{n}" } }
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Fabricator(:diff_category, from: :category) do
|
||||||
|
name "Different Category"
|
||||||
|
user
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue