mirror of
https://github.com/flarum/core.git
synced 2025-08-08 01:16:52 +02:00
update: forum/components/PostStream
This commit is contained in:
committed by
Franz Liedke
parent
2fb885175a
commit
89b6847710
@@ -8,7 +8,7 @@ import Button from '../../common/components/Button';
|
|||||||
* The `PostStream` component displays an infinitely-scrollable wall of posts in
|
* The `PostStream` component displays an infinitely-scrollable wall of posts in
|
||||||
* a discussion. Posts that have not loaded will be displayed as placeholders.
|
* a discussion. Posts that have not loaded will be displayed as placeholders.
|
||||||
*
|
*
|
||||||
* ### Props
|
* ### Attrs
|
||||||
*
|
*
|
||||||
* - `discussion`
|
* - `discussion`
|
||||||
* - `stream`
|
* - `stream`
|
||||||
@@ -16,9 +16,11 @@ import Button from '../../common/components/Button';
|
|||||||
* - `onPositionChange`
|
* - `onPositionChange`
|
||||||
*/
|
*/
|
||||||
export default class PostStream extends Component {
|
export default class PostStream extends Component {
|
||||||
init() {
|
oninit(vnode) {
|
||||||
this.discussion = this.props.discussion;
|
super.oninit(vnode);
|
||||||
this.stream = this.props.stream;
|
|
||||||
|
this.discussion = this.attrs.discussion;
|
||||||
|
this.stream = this.attrs.stream;
|
||||||
|
|
||||||
this.scrollListener = new ScrollListener(this.onscroll.bind(this));
|
this.scrollListener = new ScrollListener(this.onscroll.bind(this));
|
||||||
}
|
}
|
||||||
@@ -96,29 +98,33 @@ export default class PostStream extends Component {
|
|||||||
return <div className="PostStream">{items}</div>;
|
return <div className="PostStream">{items}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
config(isInitialized, context) {
|
onupdate(vnode) {
|
||||||
this.triggerScroll();
|
this.triggerScroll();
|
||||||
|
}
|
||||||
|
|
||||||
if (isInitialized) return;
|
oncreate(vnode) {
|
||||||
|
super.oncreate(vnode);
|
||||||
|
|
||||||
|
this.triggerScroll();
|
||||||
|
|
||||||
// This is wrapped in setTimeout due to the following Mithril issue:
|
// This is wrapped in setTimeout due to the following Mithril issue:
|
||||||
// https://github.com/lhorie/mithril.js/issues/637
|
// https://github.com/lhorie/mithril.js/issues/637
|
||||||
setTimeout(() => this.scrollListener.start());
|
setTimeout(() => this.scrollListener.start());
|
||||||
|
}
|
||||||
|
|
||||||
context.onunload = () => {
|
onremove(vnode) {
|
||||||
this.scrollListener.stop();
|
this.scrollListener.stop();
|
||||||
clearTimeout(this.calculatePositionTimeout);
|
clearTimeout(this.calculatePositionTimeout);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start scrolling, if appropriate, to a newly-targeted post.
|
* Start scrolling, if appropriate, to a newly-targeted post.
|
||||||
*/
|
*/
|
||||||
triggerScroll() {
|
triggerScroll() {
|
||||||
if (!this.props.targetPost) return;
|
if (!this.attrs.targetPost) return;
|
||||||
|
|
||||||
const oldTarget = this.prevTarget;
|
const oldTarget = this.prevTarget;
|
||||||
const newTarget = this.props.targetPost;
|
const newTarget = this.attrs.targetPost;
|
||||||
|
|
||||||
if (oldTarget) {
|
if (oldTarget) {
|
||||||
if ('number' in oldTarget && oldTarget.number === newTarget.number) return;
|
if ('number' in oldTarget && oldTarget.number === newTarget.number) return;
|
||||||
@@ -265,7 +271,7 @@ export default class PostStream extends Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (startNumber) {
|
if (startNumber) {
|
||||||
this.props.onPositionChange(startNumber || 1, endNumber, startNumber);
|
this.attrs.onPositionChange(startNumber || 1, endNumber, startNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user