From f9070177c181b7c0c06d6bb3f97748f1d69c2a6e Mon Sep 17 00:00:00 2001 From: nickago Date: Fri, 31 Jul 2015 17:20:38 -0700 Subject: Added more comments and did cosmetic refactoring to understand code easier --- web/react/components/post_list.jsx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'web/react/components') diff --git a/web/react/components/post_list.jsx b/web/react/components/post_list.jsx index e7d57df8d..7ea7202e7 100644 --- a/web/react/components/post_list.jsx +++ b/web/react/components/post_list.jsx @@ -93,6 +93,9 @@ module.exports = React.createClass({ } }); + // scrollPosistion records and holds every position that the user has been at + // Disabled by preventScrollTrigger + // Consider storing this in localStorage instead $(post_holder).scroll(function(e){ if (!self.preventScrollTrigger) { self.scrollPosition = $(post_holder).scrollTop() + $(post_holder).innerHeight(); @@ -154,13 +157,11 @@ module.exports = React.createClass({ if (this.gotMorePosts) { this.gotMorePosts = false; $(post_holder).scrollTop($(post_holder).scrollTop() + (post_holder.scrollHeight-this.oldScrollHeight) ); + } else if ($("#new_message")[0] && !this.scrolledToNew) { + $(post_holder).scrollTop($(post_holder).scrollTop() + $("#new_message").offset().top - 63); + this.scrolledToNew = true; } else { - if ($("#new_message")[0] && !this.scrolledToNew) { - $(post_holder).scrollTop($(post_holder).scrollTop() + $("#new_message").offset().top - 63); - this.scrolledToNew = true; - } else { - $(post_holder).scrollTop(post_holder.scrollHeight); - } + $(post_holder).scrollTop(post_holder.scrollHeight); } $(post_holder).perfectScrollbar('update'); }, @@ -168,10 +169,13 @@ module.exports = React.createClass({ var newState = getStateFromStores(); if (!utils.areStatesEqual(newState, this.state)) { - if (this.state.post_list && this.state.post_list.order) { - if (this.state.channel.id === newState.channel.id && this.state.post_list.order.length != newState.post_list.order.length && newState.post_list.order.length > Constants.POST_CHUNK_SIZE) { - this.gotMorePosts = true; - } + if (this.state.post_list && + this.state.post_list.order && + this.state.channel.id === newState.channel.id && + this.state.post_list.order.length !== newState.post_list.order.length && + newState.post_list.order.length > Constants.POST_CHUNK_SIZE) { + // Thus marking the end of the conditional + this.gotMorePosts = true; } if (this.state.channel.id !== newState.channel.id) { this.scrolledToNew = false; -- cgit v1.2.3-1-g7c22