From b26bc73c7880e691e77e9ca4169e9ed7735e3bc9 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Mon, 13 Jul 2015 08:32:25 -0400 Subject: should fix scrolling on forceupdate --- web/react/components/post.jsx | 2 +- web/react/components/post_list.jsx | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'web/react') diff --git a/web/react/components/post.jsx b/web/react/components/post.jsx index 04b5ba082..2d25e31e0 100644 --- a/web/react/components/post.jsx +++ b/web/react/components/post.jsx @@ -85,7 +85,7 @@ module.exports = React.createClass({
- +
diff --git a/web/react/components/post_list.jsx b/web/react/components/post_list.jsx index 177e4a1db..3409bad28 100644 --- a/web/react/components/post_list.jsx +++ b/web/react/components/post_list.jsx @@ -63,6 +63,8 @@ module.exports = React.createClass({ oldScrollHeight: 0, oldZoom: 0, scrolledToNew: false, + p: 0, + wasForced: false, componentDidMount: function() { var user = UserStore.getCurrentUser(); if (user.props && user.props.theme) { @@ -108,6 +110,12 @@ module.exports = React.createClass({ }); $(post_holder).scroll(function(e){ + if (self.wasForced) { + console.log('hit'); + $(post_holder).scrollTop(self.p); + $(post_holder).perfectScrollbar('update'); + self.wasForced = false; + } if (!self.preventScrollTrigger) { self.scrollPosition = $(post_holder).scrollTop() + $(post_holder).innerHeight(); } @@ -197,7 +205,10 @@ module.exports = React.createClass({ this.setState(newState); } else { // Updates the timestamp on each post + this.wasForced = true; + this.p = $(".post-list-holder-by-time").scrollTop(); this.forceUpdate() + //this.refs.post0.refs.info.forceUpdate(); } }, _onSocketChange: function(msg) { @@ -452,7 +463,7 @@ module.exports = React.createClass({ isLastComment = (i === 0 || posts[order[i-1]].root_id != post.root_id); } - var postCtl = ; + var postCtl = ; currentPostDay = utils.getDateForUnixTicks(post.create_at); if(currentPostDay.getDate() !== previousPostDay.getDate() || currentPostDay.getMonth() !== previousPostDay.getMonth() || currentPostDay.getFullYear() !== previousPostDay.getFullYear()) { -- cgit v1.2.3-1-g7c22 From 614992dcb7b4a4cdcedefe3ca813a03b758a97f0 Mon Sep 17 00:00:00 2001 From: nickago Date: Mon, 13 Jul 2015 08:34:34 -0700 Subject: Added timestamp updates to right side and cleaned code --- web/react/components/post.jsx | 2 +- web/react/components/post_list.jsx | 22 +++++++++++----------- web/react/components/post_right.jsx | 18 ++++++++++++++++-- 3 files changed, 28 insertions(+), 14 deletions(-) (limited to 'web/react') diff --git a/web/react/components/post.jsx b/web/react/components/post.jsx index 2d25e31e0..04b5ba082 100644 --- a/web/react/components/post.jsx +++ b/web/react/components/post.jsx @@ -85,7 +85,7 @@ module.exports = React.createClass({
- +
diff --git a/web/react/components/post_list.jsx b/web/react/components/post_list.jsx index 59f33fb4d..e186fb706 100644 --- a/web/react/components/post_list.jsx +++ b/web/react/components/post_list.jsx @@ -63,7 +63,7 @@ module.exports = React.createClass({ oldScrollHeight: 0, oldZoom: 0, scrolledToNew: false, - p: 0, + preForcePosision: 0, wasForced: false, componentDidMount: function() { var user = UserStore.getCurrentUser(); @@ -80,6 +80,7 @@ module.exports = React.createClass({ PostStore.addChangeListener(this._onChange); ChannelStore.addChangeListener(this._onChange); + UserStore.addStatusesChangeListener(this._onTimeChange); SocketStore.addChangeListener(this._onSocketChange); $(".post-list-holder-by-time").perfectScrollbar(); @@ -110,8 +111,7 @@ module.exports = React.createClass({ $(post_holder).scroll(function(e){ if (self.wasForced) { - console.log('hit'); - $(post_holder).scrollTop(self.p); + $(post_holder).scrollTop(self.preForcePosision); $(post_holder).perfectScrollbar('update'); self.wasForced = false; } @@ -165,6 +165,7 @@ module.exports = React.createClass({ componentWillUnmount: function() { PostStore.removeChangeListener(this._onChange); ChannelStore.removeChangeListener(this._onChange); + UserStore.removeStatusesChangeListener(this._onTimeChange); SocketStore.removeChangeListener(this._onSocketChange); $('body').off('click.userpopover'); }, @@ -201,13 +202,7 @@ module.exports = React.createClass({ this.scrolledToNew = false; } this.setState(newState); - } else { - // Updates the timestamp on each post - this.wasForced = true; - this.p = $(".post-list-holder-by-time").scrollTop(); - this.forceUpdate() - //this.refs.post0.refs.info.forceUpdate(); - } + } }, _onSocketChange: function(msg) { if (msg.action == "posted") { @@ -271,6 +266,11 @@ module.exports = React.createClass({ AsyncClient.getProfiles(); } }, + _onTimeChange: function() { + this.wasForced = true; + this.preForcePosision = $(".post-list-holder-by-time").scrollTop(); + this.forceUpdate() + }, getMorePosts: function(e) { e.preventDefault(); @@ -461,7 +461,7 @@ module.exports = React.createClass({ isLastComment = (i === 0 || posts[order[i-1]].root_id != post.root_id); } - var postCtl = ; + var postCtl = ; currentPostDay = utils.getDateForUnixTicks(post.create_at); if(currentPostDay.getDate() !== previousPostDay.getDate() || currentPostDay.getMonth() !== previousPostDay.getMonth() || currentPostDay.getFullYear() !== previousPostDay.getFullYear()) { diff --git a/web/react/components/post_right.jsx b/web/react/components/post_right.jsx index 115ee87d4..89a616d27 100644 --- a/web/react/components/post_right.jsx +++ b/web/react/components/post_right.jsx @@ -279,9 +279,11 @@ function getStateFromStores() { } module.exports = React.createClass({ + wasForced: false, componentDidMount: function() { PostStore.addSelectedPostChangeListener(this._onChange); PostStore.addChangeListener(this._onChangeAll); + UserStore.addStatusesChangeListener(this._onTimeChange); this.resize(); var self = this; $(window).resize(function(){ @@ -289,11 +291,15 @@ module.exports = React.createClass({ }); }, componentDidUpdate: function() { - this.resize(); + if(!this.wasForced){ + this.resize(); + wasForced = false + } }, componentWillUnmount: function() { PostStore.removeSelectedPostChangeListener(this._onChange); PostStore.removeChangeListener(this._onChangeAll); + UserStore.removeStatusesChangeListener(this._onTimeChange) }, _onChange: function() { if (this.isMounted()) { @@ -333,6 +339,14 @@ module.exports = React.createClass({ this.setState(getStateFromStores()); } }, + _onTimeChange: function() { + this.wasForced = true; + for (var key in this.refs) { + if(this.refs[key].forceUpdate != undefined) { + this.refs[key].forceUpdate(); + } + } + }, getInitialState: function() { return getStateFromStores(); }, @@ -392,7 +406,7 @@ module.exports = React.createClass({
{ posts_array.map(function(cpost) { - return + return })}
-- cgit v1.2.3-1-g7c22 From 8595b915afae9c494f09bd45692102ae86306ffe Mon Sep 17 00:00:00 2001 From: nickago Date: Mon, 13 Jul 2015 11:24:39 -0700 Subject: Fixed 'this' typo and added semicolon --- web/react/components/post_right.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/react') diff --git a/web/react/components/post_right.jsx b/web/react/components/post_right.jsx index 89a616d27..0c3754529 100644 --- a/web/react/components/post_right.jsx +++ b/web/react/components/post_right.jsx @@ -293,7 +293,7 @@ module.exports = React.createClass({ componentDidUpdate: function() { if(!this.wasForced){ this.resize(); - wasForced = false + this.wasForced = false; } }, componentWillUnmount: function() { -- cgit v1.2.3-1-g7c22 From 634df1c6242772e44fed5f64ac238adf2d0503a0 Mon Sep 17 00:00:00 2001 From: nickago Date: Tue, 14 Jul 2015 07:54:09 -0700 Subject: Added semicolons --- web/react/components/post_list.jsx | 2 +- web/react/components/post_right.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'web/react') diff --git a/web/react/components/post_list.jsx b/web/react/components/post_list.jsx index e186fb706..99b1b514a 100644 --- a/web/react/components/post_list.jsx +++ b/web/react/components/post_list.jsx @@ -269,7 +269,7 @@ module.exports = React.createClass({ _onTimeChange: function() { this.wasForced = true; this.preForcePosision = $(".post-list-holder-by-time").scrollTop(); - this.forceUpdate() + this.forceUpdate(); }, getMorePosts: function(e) { e.preventDefault(); diff --git a/web/react/components/post_right.jsx b/web/react/components/post_right.jsx index 0c3754529..ab818c1bd 100644 --- a/web/react/components/post_right.jsx +++ b/web/react/components/post_right.jsx @@ -299,7 +299,7 @@ module.exports = React.createClass({ componentWillUnmount: function() { PostStore.removeSelectedPostChangeListener(this._onChange); PostStore.removeChangeListener(this._onChangeAll); - UserStore.removeStatusesChangeListener(this._onTimeChange) + UserStore.removeStatusesChangeListener(this._onTimeChange); }, _onChange: function() { if (this.isMounted()) { -- cgit v1.2.3-1-g7c22