From 52aefa720d06fabee395d3ce33df535b5e2bb929 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Thu, 4 Apr 2024 10:28:48 +0300 Subject: [PATCH] FIX: Load category before opening composer (#26493) The "new topic" route can open the composer with a category preselected. This commit ensures that the category is loaded before the composer is opened. --- .../discourse/app/routes/new-topic.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/routes/new-topic.js b/app/assets/javascripts/discourse/app/routes/new-topic.js index cc1e57cb609..1cc1d5ea4dc 100644 --- a/app/assets/javascripts/discourse/app/routes/new-topic.js +++ b/app/assets/javascripts/discourse/app/routes/new-topic.js @@ -10,9 +10,23 @@ export default class extends DiscourseRoute { @service currentUser; @service site; - beforeModel(transition) { + async beforeModel(transition) { if (this.currentUser) { - const category = this.parseCategoryFromTransition(transition); + let category; + if (this.site.lazy_load_categories) { + if (transition.to.queryParams.category_id) { + const categories = await Category.asyncFindByIds([ + transition.to.queryParams.category_id, + ]); + category = categories[0]; + } else if (transition.to.queryParams.category) { + category = await Category.asyncFindBySlugPath( + transition.to.queryParams.category + ); + } + } else { + category = this.parseCategoryFromTransition(transition); + } if (category) { // Using URL-based transition to avoid bug with dynamic segments and refreshModel query params