Before this change we were setting the input after the query has been done, resulting in us overwriting the input if the user types during the query. We don't need to update it after the query, we just need to ensure it's set when we load the page and then it should stay in sync.
61 lines
1.5 KiB
JavaScript
61 lines
1.5 KiB
JavaScript
import Controller, { inject as controller } from "@ember/controller";
|
|
import { action } from "@ember/object";
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
|
import { equal } from "@ember/object/computed";
|
|
import { longDate } from "discourse/lib/formatter";
|
|
import { observes } from "discourse-common/utils/decorators";
|
|
|
|
export default Controller.extend({
|
|
application: controller(),
|
|
queryParams: ["period", "order", "asc", "name", "group", "exclude_usernames"],
|
|
period: "weekly",
|
|
order: "likes_received",
|
|
asc: null,
|
|
name: "",
|
|
group: null,
|
|
nameInput: null,
|
|
exclude_usernames: null,
|
|
isLoading: false,
|
|
|
|
showTimeRead: equal("period", "all"),
|
|
|
|
loadUsers(params) {
|
|
this.set("isLoading", true);
|
|
|
|
this.set("nameInput", params.name);
|
|
|
|
this.store
|
|
.find("directoryItem", params)
|
|
.then((model) => {
|
|
const lastUpdatedAt = model.get("resultSetMeta.last_updated_at");
|
|
this.setProperties({
|
|
model,
|
|
lastUpdatedAt: lastUpdatedAt ? longDate(lastUpdatedAt) : null,
|
|
period: params.period,
|
|
});
|
|
})
|
|
.finally(() => {
|
|
this.set("isLoading", false);
|
|
});
|
|
},
|
|
|
|
@action
|
|
onFilterChanged(filter) {
|
|
discourseDebounce(this, this._setName, filter, 500);
|
|
},
|
|
|
|
_setName(name) {
|
|
this.set("name", name);
|
|
},
|
|
|
|
@observes("model.canLoadMore")
|
|
_showFooter() {
|
|
this.set("application.showFooter", !this.get("model.canLoadMore"));
|
|
},
|
|
|
|
@action
|
|
loadMore() {
|
|
this.model.loadMore();
|
|
},
|
|
});
|