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.
This commit is contained in:
Bianca Nenciu 2024-04-04 10:28:48 +03:00 committed by GitHub
parent 339893812b
commit 52aefa720d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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