Skip to content

A platform for community discussion. Free, open, simple.

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

Daniel Waterworth720101b3ee89
diff --git a/app/assets/javascripts/discourse/models/category-list.js.es6 b/app/assets/javascripts/discourse/models/category-list.js.es6
index f04b40dff80..b8437f706dd 100644
--- a/app/assets/javascripts/discourse/models/category-list.js.es6
+++ b/app/assets/javascripts/discourse/models/category-list.js.es6
@@ -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;
},
diff --git a/app/assets/javascripts/discourse/models/site.js.es6 b/app/assets/javascripts/discourse/models/site.js.es6
index aa7a2b5ded6..5f9065d3d88 100644
--- a/app/assets/javascripts/discourse/models/site.js.es6
+++ b/app/assets/javascripts/discourse/models/site.js.es6
@@ -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;
}
}
});
diff --git a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 b/app/assets/javascripts/discourse/routes/build-category-route.js.es6
index b19c91b34f5..d360c11eb05 100644
--- a/app/assets/javascripts/discourse/routes/build-category-route.js.es6
+++ b/app/assets/javascripts/discourse/routes/build-category-route.js.es6
@@ -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) {