DEV: minor refactoring or jump-to-post (#15312)

- replaces alias by reads
- drops jquery usage
- autofocus should already be done; so remove custom code
- uses @action
This commit is contained in:
Joffrey JAFFEUX 2021-12-15 12:09:26 +01:00 committed by GitHub
parent 88fa8b5848
commit 666d291b24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,26 +1,21 @@
import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import { alias } from "@ember/object/computed";
import { next } from "@ember/runloop";
import { reads } from "@ember/object/computed";
import { action } from "@ember/object";
export default Controller.extend(ModalFunctionality, {
model: null,
postNumber: null,
postDate: null,
filteredPostsCount: alias("topic.postStream.filteredPostsCount"),
filteredPostsCount: reads("topic.postStream.filteredPostsCount"),
onShow() {
next(() => $("#post-jump").focus());
},
actions: {
jump() {
if (this.postNumber) {
this._jumpToIndex(this.filteredPostsCount, this.postNumber);
} else if (this.postDate) {
this._jumpToDate(this.postDate);
}
},
@action
jump() {
if (this.postNumber) {
this._jumpToIndex(this.filteredPostsCount, this.postNumber);
} else if (this.postDate) {
this._jumpToDate(this.postDate);
}
},
_jumpToIndex(postsCounts, postNumber) {