summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornickago <ngonella@calpoly.edu>2015-07-31 17:20:38 -0700
committernickago <ngonella@calpoly.edu>2015-08-12 09:28:54 -0700
commitf9070177c181b7c0c06d6bb3f97748f1d69c2a6e (patch)
treecc29bde60042f0eeef69a69e21768faffeac7cbf
parentea4250bbbc21492a7f114daca30d839bc7644e90 (diff)
downloadchat-f9070177c181b7c0c06d6bb3f97748f1d69c2a6e.tar.gz
chat-f9070177c181b7c0c06d6bb3f97748f1d69c2a6e.tar.bz2
chat-f9070177c181b7c0c06d6bb3f97748f1d69c2a6e.zip
Added more comments and did cosmetic refactoring to understand code easier
-rw-r--r--web/react/components/post_list.jsx24
1 files changed, 14 insertions, 10 deletions
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;