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/users.js
Joffrey JAFFEUX 8ee3d2d954
FIX: prevents debouncing and query to override each other (#11704)
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.
2021-01-14 10:19:08 +01:00

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();
},
});