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:
Bianca Nenciu
2024-01-10 20:30:59 +02:00
committed by GitHub
parent 0d52331823
commit c916806fe8
4 changed files with 26 additions and 0 deletions

View File

@@ -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;
});

View File

@@ -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