DEV: Remove jQuery animate calls (#15321)

Affects j/k navigation and PM interaction with @discobot.
This commit is contained in:
Penar Musaraj
2021-12-16 11:00:09 -05:00
committed by GitHub
parent 9365c4b364
commit 48b7696dbc
3 changed files with 70 additions and 54 deletions

View File

@@ -19,10 +19,8 @@ import bootbox from "bootbox";
import { bufferedProperty } from "discourse/mixins/buffered-content";
import { buildQuote } from "discourse/lib/quote";
import { deepMerge } from "discourse-common/lib/object";
import discourseDebounce from "discourse-common/lib/debounce";
import { escapeExpression } from "discourse/lib/utilities";
import { extractLinkMeta } from "discourse/lib/render-topic-featured-link";
import isElementInViewport from "discourse/lib/is-element-in-viewport";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { inject as service } from "@ember/service";
import showModal from "discourse/lib/show-modal";
@@ -1679,52 +1677,11 @@ export default Controller.extend(bufferedProperty("model"), {
}
}
}
// scroll to bottom is very specific to new posts from discobot
// hence the -2 check (discobot id). We can shift all this code
// to discobot plugin longer term
if (
topic.get("isPrivateMessage") &&
this.currentUser &&
this.currentUser.get("id") !== data.user_id &&
data.user_id === -2 &&
data.type === "created"
) {
const postNumber = data.post_number;
const notInPostStream =
topic.get("highest_post_number") <= postNumber;
const postNumberDifference = postNumber - topic.get("currentPost");
if (
notInPostStream &&
postNumberDifference > 0 &&
postNumberDifference < 7
) {
this._scrollToPost(data.post_number);
}
}
},
this.get("model.message_bus_last_id")
);
},
_scrollToPost(postNumber) {
discourseDebounce(
this,
function () {
const $post = $(`.topic-post article#post_${postNumber}`);
if ($post.length === 0 || isElementInViewport($post[0])) {
return;
}
$("html, body").animate({ scrollTop: $post.offset().top }, 1000);
},
postNumber,
500
);
},
unsubscribe() {
// never unsubscribe when navigating from topic to topic
if (!this.get("model.id")) {

View File

@@ -708,10 +708,11 @@ export default {
}
},
_scrollTo(scrollTop, complete) {
$("html, body")
.stop(true, true)
.animate({ scrollTop }, { duration: animationDuration, complete });
_scrollTo(scrollTop) {
window.scrollTo({
top: scrollTop,
behavior: "smooth",
});
},
_scrollList($article) {
@@ -738,13 +739,7 @@ export default {
scrollPos = 0;
}
if (this._scrollAnimation) {
this._scrollAnimation.stop();
}
this._scrollAnimation = $("html, body").animate(
{ scrollTop: scrollPos + "px" },
animationDuration
);
this._scrollTo(scrollPos);
},
categoriesTopicsList() {