diff options
author | JoramWilander <jwawilander@gmail.com> | 2015-09-11 08:38:18 -0400 |
---|---|---|
committer | JoramWilander <jwawilander@gmail.com> | 2015-09-11 08:38:18 -0400 |
commit | 83931da9f2b3eb5e8dc835313992c7ba2ea65f4a (patch) | |
tree | 0888dbaeb27f0c5517060ab298b27b62f0397694 /web/react/components/post_list.jsx | |
parent | 27e8b28672ede105044b19e2aebcf2f2ff51de28 (diff) | |
download | chat-83931da9f2b3eb5e8dc835313992c7ba2ea65f4a.tar.gz chat-83931da9f2b3eb5e8dc835313992c7ba2ea65f4a.tar.bz2 chat-83931da9f2b3eb5e8dc835313992c7ba2ea65f4a.zip |
Fix load more posts bug.
Diffstat (limited to 'web/react/components/post_list.jsx')
-rw-r--r-- | web/react/components/post_list.jsx | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/web/react/components/post_list.jsx b/web/react/components/post_list.jsx index 9d95887d9..e6aa3f8df 100644 --- a/web/react/components/post_list.jsx +++ b/web/react/components/post_list.jsx @@ -189,9 +189,15 @@ export default class PostList extends React.Component { this.scrollToBottom(true); // the user clicked 'load more messages' - } else if (this.gotMorePosts) { - var lastPost = oldPosts[oldOrder[prevState.numToDisplay]]; - $('#' + lastPost.id)[0].scrollIntoView(); + } else if (this.gotMorePosts && oldOrder.length > 0) { + let index; + if (prevState.numToDisplay >= oldOrder.length) { + index = oldOrder.length - 1; + } else { + index = prevState.numToDisplay; + } + const lastPost = oldPosts[oldOrder[index]]; + $('#post_' + lastPost.id)[0].scrollIntoView(); this.gotMorePosts = false; } else { this.scrollTo(this.prevScrollTop); |