discourse/app/assets/javascripts/admin/addon/controllers/admin-site-text-index.js
Roman Rizzi 8b426431a4
DEV: Wrap Ember.run.debounce. (#11352)
We want to wrap the `Ember.run.debounce` function and internally call `Ember.run` instead when running tests.

This commit changes discourseDebounce to work the same way as `Ember.run.debounce`.

Now that `discourseDebounce` works exactly like `Ember.run.debounce`, let's replace it and only use `DiscourseDebounce` from now on.

Move debounce to discourse-common to be able to reuse it in different bundles

Keep old debounce file for backwards-compatibility
2020-12-10 11:01:42 -03:00

44 lines
1015 B
JavaScript

import Controller from "@ember/controller";
import discourseDebounce from "discourse-common/lib/debounce";
let lastSearch;
export default Controller.extend({
searching: false,
siteTexts: null,
preferred: false,
queryParams: ["q", "overridden"],
q: null,
overridden: false,
_performSearch() {
this.store
.find("site-text", this.getProperties("q", "overridden"))
.then((results) => {
this.set("siteTexts", results);
})
.finally(() => this.set("searching", false));
},
actions: {
edit(siteText) {
this.transitionToRoute("adminSiteText.edit", siteText.get("id"));
},
toggleOverridden() {
this.toggleProperty("overridden");
this.set("searching", true);
discourseDebounce(this, this._performSearch, 400);
},
search() {
const q = this.q;
if (q !== lastSearch) {
this.set("searching", true);
discourseDebounce(this, this._performSearch, 400);
lastSearch = q;
}
},
},
});