1
0
mirror of https://github.com/flarum/core.git synced 2025-06-25 12:14:13 +02:00

Fix DiscussionListPane jumping around (#2402)

Ensure that scroll position is retained between page changes, so if navigating via the sidebar, you don't need to re-scroll down every time.
This commit is contained in:
Wadim Kalmykov
2021-01-14 05:49:26 +07:00
committed by GitHub
parent 85210ff6a1
commit 2e3197d510

View File

@ -1,5 +1,6 @@
import DiscussionList from './DiscussionList'; import DiscussionList from './DiscussionList';
import Component from '../../common/Component'; import Component from '../../common/Component';
import DiscussionPage from './DiscussionPage';
const hotEdge = (e) => { const hotEdge = (e) => {
if (e.pageX < 10) app.pane.show(); if (e.pageX < 10) app.pane.show();
@ -36,6 +37,12 @@ export default class DiscussionListPane extends Component {
$(document).on('mousemove', hotEdge); $(document).on('mousemove', hotEdge);
// When coming from another discussion, scroll to the previous postition
// to prevent the discussion list jumping around.
if (app.previous.matches(DiscussionPage)) {
const top = app.cache.discussionListPaneScrollTop || 0;
$list.scrollTop(top);
} else {
// If the discussion we are viewing is listed in the discussion list, then // If the discussion we are viewing is listed in the discussion list, then
// we will make sure it is visible in the viewport if it is not we will // we will make sure it is visible in the viewport if it is not we will
// scroll the list down to it. // scroll the list down to it.
@ -51,8 +58,10 @@ export default class DiscussionListPane extends Component {
} }
} }
} }
}
onremove() { onremove(vnode) {
app.cache.discussionListPaneScrollTop = $(vnode.dom).scrollTop();
$(document).off('mousemove', hotEdge); $(document).off('mousemove', hotEdge);
} }