mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Serialize categories when viewing a topic (#25206)
When navigating straight to a topic the category was not displayed at all because the categories were not loaded. Similarly, the categories for suggested topics were not loaded either. This commit adds a list of categories to topic view model class and serializer.
This commit is contained in:
@@ -36,6 +36,7 @@ export function loadTopicView(topic, args) {
|
||||
return PreloadStore.getAndRemove(`topic_${topic.id}`, () =>
|
||||
ajax(jsonUrl, { data })
|
||||
).then((json) => {
|
||||
json.categories?.forEach((c) => topic.site.updateCategory(c));
|
||||
topic.updateFromJson(json);
|
||||
return json;
|
||||
});
|
||||
|
||||
@@ -83,6 +83,7 @@ class TopicViewSerializer < ApplicationSerializer
|
||||
|
||||
has_one :details, serializer: TopicViewDetailsSerializer, root: false, embed: :objects
|
||||
has_many :pending_posts, serializer: TopicPendingPostSerializer, root: false, embed: :objects
|
||||
has_many :categories, serializer: TopicCategorySerializer, embed: :objects
|
||||
|
||||
has_one :published_page, embed: :objects
|
||||
|
||||
@@ -316,4 +317,8 @@ class TopicViewSerializer < ApplicationSerializer
|
||||
def summarizable
|
||||
object.summarizable?
|
||||
end
|
||||
|
||||
def include_categories?
|
||||
SiteSetting.lazy_load_categories
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user