FIX: Update site data when we receive a list of categories

When we receive a list of categories, we should store them so that we
are able to query them in the browser without a page refresh.

This removes a previous fix for the same issue that was much less
general.
This commit is contained in:
Daniel Waterworth 2019-11-25 16:42:01 +00:00
parent 5c5d8a307a
commit 720101b3ee
3 changed files with 9 additions and 23 deletions

View File

@ -2,6 +2,7 @@ import PreloadStore from "preload-store";
import { ajax } from "discourse/lib/ajax";
import Topic from "discourse/models/topic";
import Category from "discourse/models/category";
import Site from "discourse/models/site";
const CategoryList = Ember.ArrayProxy.extend({
init() {
@ -76,7 +77,9 @@ CategoryList.reopenClass({
break;
}
categories.pushObject(store.createRecord("category", c));
const record = Site.current().updateCategory(c);
record.setupGroupsAndPermissions();
categories.pushObject(record);
});
return categories;
},

View File

@ -87,7 +87,7 @@ const Site = RestModel.extend({
},
// Returns it in the correct order, by setting
@discourseComputed
@discourseComputed("categories.[]")
categoriesList() {
return this.siteSettings.fixed_category_positions
? this.categories
@ -123,11 +123,13 @@ const Site = RestModel.extend({
if (existingCategory) {
existingCategory.setProperties(newCategory);
return existingCategory;
} else {
// TODO insert in right order?
newCategory = this.store.createRecord("category", newCategory);
categories.pushObject(newCategory);
this.categoriesById[categoryId] = newCategory;
return newCategory;
}
}
});

View File

@ -21,28 +21,9 @@ export default (filterArg, params) => {
modelParams.slug,
modelParams.parentSlug
);
if (!category) {
return Category.reloadBySlug(
modelParams.slug,
modelParams.parentSlug
).then(atts => {
if (modelParams.parentSlug) {
atts.category.parentCategory = Category.findBySlug(
modelParams.parentSlug
);
}
const record = this.store.createRecord("category", atts.category);
record.setupGroupsAndPermissions();
this.site.updateCategory(record);
return {
category: Category.findBySlug(
modelParams.slug,
modelParams.parentSlug
)
};
});
if (category) {
return { category };
}
return { category };
},
afterModel(model, transition) {