A platform for community discussion. Free, open, simple.
FEATURE: Restore scroll on user activity pages (#16661)
Bianca Nenciu618a1ba5711a
diff --git a/app/assets/javascripts/discourse/app/components/bookmark-list.js b/app/assets/javascripts/discourse/app/components/bookmark-list.jsindex 9559c87a7e2..17e07f858e4 100644--- a/app/assets/javascripts/discourse/app/components/bookmark-list.js+++ b/app/assets/javascripts/discourse/app/components/bookmark-list.js@@ -2,7 +2,6 @@ import Component from "@ember/component";import { action } from "@ember/object";import { schedule } from "@ember/runloop";import bootbox from "bootbox";-import discourseDebounce from "discourse-common/lib/debounce";import { openBookmarkModal } from "discourse/controllers/bookmark";import { ajax } from "discourse/lib/ajax";import {@@ -28,18 +27,12 @@ export default Component.extend(Scrolling, {},scrollToLastPosition() {- let scrollTo = this.session.bookmarkListScrollPosition;- if (scrollTo && scrollTo >= 0) {+ const scrollTo = this.session.bookmarkListScrollPosition;+ if (scrollTo > 0) {schedule("afterRender", () => {- discourseDebounce(- this,- function () {- if (this.element && !this.isDestroying && !this.isDestroyed) {- window.scrollTo(0, scrollTo + 1);- }- },- 0- );+ if (this.element && !this.isDestroying && !this.isDestroyed) {+ window.scrollTo(0, scrollTo + 1);+ }});}},diff --git a/app/assets/javascripts/discourse/app/components/discovery-topics-list.js b/app/assets/javascripts/discourse/app/components/discovery-topics-list.jsindex b0da8c5924e..4683d8e8c18 100644--- a/app/assets/javascripts/discourse/app/components/discovery-topics-list.js+++ b/app/assets/javascripts/discourse/app/components/discovery-topics-list.js@@ -13,8 +13,8 @@ export default Component.extend(UrlRefresh, LoadMore, {@on("didInsertElement")@observes("model")_readjustScrollPosition() {- const scrollTo = this.session.get("topicListScrollPosition");- if (scrollTo && scrollTo >= 0) {+ const scrollTo = this.session.topicListScrollPosition;+ if (scrollTo > 0) {schedule("afterRender", () => $(window).scrollTop(scrollTo + 1));} else {scheduleOnce("afterRender", this, this.loadMoreUnlessFull);diff --git a/app/assets/javascripts/discourse/app/components/topic-list.js b/app/assets/javascripts/discourse/app/components/topic-list.jsindex 67357e44699..d542aa6d535 100644--- a/app/assets/javascripts/discourse/app/components/topic-list.js+++ b/app/assets/javascripts/discourse/app/components/topic-list.js@@ -2,7 +2,6 @@ import { alias, and, reads } from "@ember/object/computed";import discourseComputed, { observes } from "discourse-common/utils/decorators";import Component from "@ember/component";import LoadMore from "discourse/mixins/load-more";-import discourseDebounce from "discourse-common/lib/debounce";import { on } from "@ember/object/evented";import { schedule } from "@ember/runloop";import showModal from "discourse/lib/show-modal";@@ -75,18 +74,12 @@ export default Component.extend(LoadMore, {return;}- let scrollTo = this.session.get("topicListScrollPosition");- if (scrollTo && scrollTo >= 0) {+ const scrollTo = this.session.topicListScrollPosition;+ if (scrollTo > 0) {schedule("afterRender", () => {- discourseDebounce(- this,- function () {- if (this.element && !this.isDestroying && !this.isDestroyed) {- $(window).scrollTop(scrollTo + 1);- }- },- 0- );+ if (this.element && !this.isDestroying && !this.isDestroyed) {+ $(window).scrollTop(scrollTo + 1);+ }});}},diff --git a/app/assets/javascripts/discourse/app/components/user-stream.js b/app/assets/javascripts/discourse/app/components/user-stream.jsindex 6e45c375c76..63273f7224c 100644--- a/app/assets/javascripts/discourse/app/components/user-stream.js+++ b/app/assets/javascripts/discourse/app/components/user-stream.js@@ -48,6 +48,7 @@ export default Component.extend(LoadMore, {return ClickTrack.trackClick(e, this.siteSettings);});this._updateLastDecoratedElement();+ this._scrollToLastPosition();}),// This view is being removed. Shut down operations@@ -71,6 +72,22 @@ export default Component.extend(LoadMore, {this._lastDecoratedElement = lastElement;},+ _scrollToLastPosition() {+ const scrollTo = this.session.userStreamScrollPosition;+ if (scrollTo > 0) {+ schedule("afterRender", () => {+ if (this.element && !this.isDestroying && !this.isDestroyed) {+ window.scrollTo(0, scrollTo + 1);+ }+ });+ }+ },++ scrolled() {+ this._super(...arguments);+ this.session.set("userStreamScrollPosition", window.scrollY);+ },+actions: {removeBookmark(userAction) {const stream = this.stream;diff --git a/app/assets/javascripts/discourse/app/routes/user-activity-stream.js b/app/assets/javascripts/discourse/app/routes/user-activity-stream.jsindex f0e1287d378..fa12c7d036d 100644--- a/app/assets/javascripts/discourse/app/routes/user-activity-stream.js+++ b/app/assets/javascripts/discourse/app/routes/user-activity-stream.js@@ -23,6 +23,10 @@ export default DiscourseRoute.extend(ViewingActionType, {},afterModel(model, transition) {+ if (!this.isPoppedState(transition)) {+ this.session.set("userStreamScrollPosition", null);+ }+return model.stream.filterBy({filter: this.userActionType,actingUsername: transition.to.queryParams.acting_username,diff --git a/app/assets/javascripts/discourse/app/routes/user-activity.js b/app/assets/javascripts/discourse/app/routes/user-activity.jsindex bec47aaaa33..9a94a47d8df 100644--- a/app/assets/javascripts/discourse/app/routes/user-activity.js+++ b/app/assets/javascripts/discourse/app/routes/user-activity.js@@ -10,6 +10,12 @@ export default DiscourseRoute.extend({return user;},+ afterModel(_model, transition) {+ if (!this.isPoppedState(transition)) {+ this.session.set("userStreamScrollPosition", null);+ }+ },+setupController(controller, user) {this.controllerFor("user-activity").set("model", user);},