mirror of
https://github.com/flarum/core.git
synced 2025-08-14 12:24:33 +02:00
Encapsulate viewingEnd() in state
...instead of calculating this derived value outside the state class.
This commit is contained in:
@@ -45,7 +45,7 @@ export default class PostStream extends Component {
|
|||||||
let lastTime;
|
let lastTime;
|
||||||
|
|
||||||
this.state.visibleEnd = this.state.sanitizeIndex(this.state.visibleEnd);
|
this.state.visibleEnd = this.state.sanitizeIndex(this.state.visibleEnd);
|
||||||
this.state.viewingEnd = this.state.visibleEnd === this.state.count();
|
const viewingEnd = this.state.viewingEnd();
|
||||||
|
|
||||||
const posts = this.state.posts();
|
const posts = this.state.posts();
|
||||||
const postIds = this.state.discussion.postIds();
|
const postIds = this.state.discussion.postIds();
|
||||||
@@ -94,7 +94,7 @@ export default class PostStream extends Component {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!this.state.viewingEnd && posts[this.state.visibleEnd - this.state.visibleStart - 1]) {
|
if (!viewingEnd && posts[this.state.visibleEnd - this.state.visibleStart - 1]) {
|
||||||
items.push(
|
items.push(
|
||||||
<div className="PostStream-loadMore" key="loadMore">
|
<div className="PostStream-loadMore" key="loadMore">
|
||||||
<Button className="Button" onclick={this.state.loadNext.bind(this)}>
|
<Button className="Button" onclick={this.state.loadNext.bind(this)}>
|
||||||
@@ -106,7 +106,7 @@ export default class PostStream extends Component {
|
|||||||
|
|
||||||
// If we're viewing the end of the discussion, the user can reply, and
|
// If we're viewing the end of the discussion, the user can reply, and
|
||||||
// is not already doing so, then show a 'write a reply' placeholder.
|
// is not already doing so, then show a 'write a reply' placeholder.
|
||||||
if (this.state.viewingEnd && (!app.session.user || this.state.discussion.canReply())) {
|
if (viewingEnd && (!app.session.user || this.state.discussion.canReply())) {
|
||||||
items.push(
|
items.push(
|
||||||
<div className="PostStream-item" key="reply">
|
<div className="PostStream-item" key="reply">
|
||||||
{ReplyPlaceholder.component({ discussion: this.state.discussion })}
|
{ReplyPlaceholder.component({ discussion: this.state.discussion })}
|
||||||
|
@@ -148,6 +148,15 @@ class PostStreamState {
|
|||||||
return this.discussion.postIds().length;
|
return this.discussion.postIds().length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Are we currently viewing the end of the discussion?
|
||||||
|
*
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
viewingEnd() {
|
||||||
|
return this.visibleEnd === this.count();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure that the given index is not outside of the possible range of
|
* Make sure that the given index is not outside of the possible range of
|
||||||
* indexes in the discussion.
|
* indexes in the discussion.
|
||||||
@@ -166,7 +175,7 @@ class PostStreamState {
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
update() {
|
update() {
|
||||||
if (!this.viewingEnd) return m.deferred().resolve().promise;
|
if (!this.viewingEnd()) return m.deferred().resolve().promise;
|
||||||
|
|
||||||
this.visibleEnd = this.count();
|
this.visibleEnd = this.count();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user