1
0
mirror of https://github.com/flarum/core.git synced 2025-08-07 17:07:19 +02:00

add forum/components/DiscussionListPane

- Extract this from DiscussionPage
This commit is contained in:
Alexander Skvortsov
2020-08-09 22:59:30 -04:00
committed by Franz Liedke
parent 095dce9a3e
commit edca7b93ec

View File

@@ -0,0 +1,46 @@
import DiscussionList from './DiscussionList';
const hotEdge = (e) => {
if (e.pageX < 10) app.pane.show();
};
export default class DiscussionListPane {
view() {
if (!app.discussions.hasDiscussions()) {
return;
}
return <div className="DiscussionPage-list">{!$('.App-navigation').is(':visible') && <DiscussionList state={app.discussions} />}</div>;
}
onupdate(vnode) {
const $list = $(vnode.dom);
// When the mouse enters and leaves the discussions pane, we want to show
// and hide the pane respectively. We also create a 10px 'hot edge' on the
// left of the screen to activate the pane.
const pane = app.pane;
$list.hover(pane.show.bind(pane), pane.onmouseleave.bind(pane));
$(document).on('mousemove', hotEdge);
// 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
// scroll the list down to it.
const $discussion = $list.find('.DiscussionListItem.active');
if ($discussion.length) {
const listTop = $list.offset().top;
const listBottom = listTop + $list.outerHeight();
const discussionTop = $discussion.offset().top;
const discussionBottom = discussionTop + $discussion.outerHeight();
if (discussionTop < listTop || discussionBottom > listBottom) {
$list.scrollTop($list.scrollTop() - listTop + discussionTop);
}
}
}
onremove(vnode) {
$(document).off('mousemove', hotEdge);
}
}