diff --git a/plugins/chat/assets/javascripts/discourse/components/channels-list.js b/plugins/chat/assets/javascripts/discourse/components/channels-list.js index ae145525a02..a1e42f0c1b8 100644 --- a/plugins/chat/assets/javascripts/discourse/components/channels-list.js +++ b/plugins/chat/assets/javascripts/discourse/components/channels-list.js @@ -92,19 +92,16 @@ export default class ChannelsList extends Component { @action storeScrollPosition() { - const scroller = document.querySelector(".channels-list"); - if (scroller) { - const scrollTop = scroller.scrollTop || 0; - this.session.set("channels-list-position", scrollTop); - } + const scrollTop = document.querySelector(".channels-list")?.scrollTop || 0; + this.session.channelsListPosition = scrollTop; } @bind _applyScrollPosition() { - const data = this.session.get("channels-list-position"); - if (data) { - const scroller = document.querySelector(".channels-list"); - scroller.scrollTo(0, data); - } + const position = this.chatStateManager.isFullPage + ? this.session.channelsListPosition || 0 + : 0; + const scroller = document.querySelector(".channels-list"); + scroller.scrollTo(0, position); } } diff --git a/plugins/chat/assets/javascripts/discourse/templates/components/channels-list.hbs b/plugins/chat/assets/javascripts/discourse/templates/components/channels-list.hbs index f63caef0ecf..a03264533ef 100644 --- a/plugins/chat/assets/javascripts/discourse/templates/components/channels-list.hbs +++ b/plugins/chat/assets/javascripts/discourse/templates/components/channels-list.hbs @@ -8,7 +8,7 @@ role="region" aria-label={{i18n "chat.aria_roles.channels_list"}} class="channels-list" - {{on "scroll" (action "storeScrollPosition")}} + {{on "scroll" (if this.chatStateManager.isFullPage this.storeScrollPosition (noop))}} > {{#if this.displayPublicChannels}}