mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 05:29:17 -06:00
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:
parent
5c5d8a307a
commit
720101b3ee
@ -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;
|
||||
},
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user