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
1 changed files with 10 additions and 15 deletions

View File

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