This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/controllers/groups-index.js
Roman Rizzi 142e0ae062
Revert "Revert "DEV: Wrap Ember.run.debounce. (#11352)"" (#11509)
* Revert "Revert "DEV: Wrap `Ember.run.debounce`. (#11352)" (#11465)"

This reverts commit aa0d4ea764.

* Correctly debounce onScroll function
2020-12-18 10:18:52 -03:00

65 lines
1.5 KiB
JavaScript

import Controller, { inject as controller } from "@ember/controller";
import I18n from "I18n";
import { INPUT_DELAY } from "discourse-common/config/environment";
import { action } from "@ember/object";
import discourseComputed from "discourse-common/utils/decorators";
import discourseDebounce from "discourse-common/lib/debounce";
export default Controller.extend({
application: controller(),
queryParams: ["order", "asc", "filter", "type"],
order: null,
asc: null,
filter: "",
type: null,
groups: null,
isLoading: false,
@discourseComputed("groups.extras.type_filters")
types(typeFilters) {
const types = [];
if (typeFilters) {
typeFilters.forEach((type) =>
types.push({ id: type, name: I18n.t(`groups.index.${type}_groups`) })
);
}
return types;
},
loadGroups(params) {
this.set("isLoading", true);
this.store
.findAll("group", params)
.then((groups) => {
this.set("groups", groups);
if (groups.canLoadMore) {
this.set("application.showFooter", !groups.canLoadMore);
}
})
.finally(() => this.set("isLoading", false));
},
@action
onFilterChanged(filter) {
discourseDebounce(this, this._debouncedFilter, filter, INPUT_DELAY);
},
@action
loadMore() {
this.groups && this.groups.loadMore();
},
@action
new() {
this.transitionToRoute("groups.new");
},
_debouncedFilter(filter) {
this.set("filter", filter);
},
});