Added timestamp updates to right side and cleaned code

Этот коммит содержится в:
nickago
2015-07-13 08:34:34 -07:00
родитель b63d42c2c6
Коммит 614992dcb7
3 изменённых файлов: 28 добавлений и 14 удалений

Просмотреть файл

@@ -85,7 +85,7 @@ module.exports = React.createClass({
<div className="post__content"> <div className="post__content">
<PostHeader post={post} sameRoot={this.props.sameRoot} commentCount={commentCount} handleCommentClick={this.handleCommentClick} isLastComment={this.props.isLastComment} /> <PostHeader post={post} sameRoot={this.props.sameRoot} commentCount={commentCount} handleCommentClick={this.handleCommentClick} isLastComment={this.props.isLastComment} />
<PostBody post={post} sameRoot={this.props.sameRoot} parentPost={parentPost} posts={posts} handleCommentClick={this.handleCommentClick} /> <PostBody post={post} sameRoot={this.props.sameRoot} parentPost={parentPost} posts={posts} handleCommentClick={this.handleCommentClick} />
<PostInfo ref="info" post={post} sameRoot={this.props.sameRoot} commentCount={commentCount} handleCommentClick={this.handleCommentClick} allowReply="true" /> <PostInfo post={post} sameRoot={this.props.sameRoot} commentCount={commentCount} handleCommentClick={this.handleCommentClick} allowReply="true" />
</div> </div>
</div> </div>
</div> </div>

Просмотреть файл

@@ -63,7 +63,7 @@ module.exports = React.createClass({
oldScrollHeight: 0, oldScrollHeight: 0,
oldZoom: 0, oldZoom: 0,
scrolledToNew: false, scrolledToNew: false,
p: 0, preForcePosision: 0,
wasForced: false, wasForced: false,
componentDidMount: function() { componentDidMount: function() {
var user = UserStore.getCurrentUser(); var user = UserStore.getCurrentUser();
@@ -80,6 +80,7 @@ module.exports = React.createClass({
PostStore.addChangeListener(this._onChange); PostStore.addChangeListener(this._onChange);
ChannelStore.addChangeListener(this._onChange); ChannelStore.addChangeListener(this._onChange);
UserStore.addStatusesChangeListener(this._onTimeChange);
SocketStore.addChangeListener(this._onSocketChange); SocketStore.addChangeListener(this._onSocketChange);
$(".post-list-holder-by-time").perfectScrollbar(); $(".post-list-holder-by-time").perfectScrollbar();
@@ -110,8 +111,7 @@ module.exports = React.createClass({
$(post_holder).scroll(function(e){ $(post_holder).scroll(function(e){
if (self.wasForced) { if (self.wasForced) {
console.log('hit'); $(post_holder).scrollTop(self.preForcePosision);
$(post_holder).scrollTop(self.p);
$(post_holder).perfectScrollbar('update'); $(post_holder).perfectScrollbar('update');
self.wasForced = false; self.wasForced = false;
} }
@@ -165,6 +165,7 @@ module.exports = React.createClass({
componentWillUnmount: function() { componentWillUnmount: function() {
PostStore.removeChangeListener(this._onChange); PostStore.removeChangeListener(this._onChange);
ChannelStore.removeChangeListener(this._onChange); ChannelStore.removeChangeListener(this._onChange);
UserStore.removeStatusesChangeListener(this._onTimeChange);
SocketStore.removeChangeListener(this._onSocketChange); SocketStore.removeChangeListener(this._onSocketChange);
$('body').off('click.userpopover'); $('body').off('click.userpopover');
}, },
@@ -201,13 +202,7 @@ module.exports = React.createClass({
this.scrolledToNew = false; this.scrolledToNew = false;
} }
this.setState(newState); 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) { _onSocketChange: function(msg) {
if (msg.action == "posted") { if (msg.action == "posted") {
@@ -271,6 +266,11 @@ module.exports = React.createClass({
AsyncClient.getProfiles(); AsyncClient.getProfiles();
} }
}, },
_onTimeChange: function() {
this.wasForced = true;
this.preForcePosision = $(".post-list-holder-by-time").scrollTop();
this.forceUpdate()
},
getMorePosts: function(e) { getMorePosts: function(e) {
e.preventDefault(); e.preventDefault();
@@ -461,7 +461,7 @@ module.exports = React.createClass({
isLastComment = (i === 0 || posts[order[i-1]].root_id != post.root_id); isLastComment = (i === 0 || posts[order[i-1]].root_id != post.root_id);
} }
var postCtl = <Post ref={"post"+(order.length-i-1)}sameUser={sameUser} sameRoot={sameRoot} post={post} parentPost={parentPost} key={post.id} posts={posts} hideProfilePic={hideProfilePic} isLastComment={isLastComment} />; var postCtl = <Post sameUser={sameUser} sameRoot={sameRoot} post={post} parentPost={parentPost} key={post.id} posts={posts} hideProfilePic={hideProfilePic} isLastComment={isLastComment} />;
currentPostDay = utils.getDateForUnixTicks(post.create_at); currentPostDay = utils.getDateForUnixTicks(post.create_at);
if(currentPostDay.getDate() !== previousPostDay.getDate() || currentPostDay.getMonth() !== previousPostDay.getMonth() || currentPostDay.getFullYear() !== previousPostDay.getFullYear()) { if(currentPostDay.getDate() !== previousPostDay.getDate() || currentPostDay.getMonth() !== previousPostDay.getMonth() || currentPostDay.getFullYear() !== previousPostDay.getFullYear()) {

Просмотреть файл

@@ -279,9 +279,11 @@ function getStateFromStores() {
} }
module.exports = React.createClass({ module.exports = React.createClass({
wasForced: false,
componentDidMount: function() { componentDidMount: function() {
PostStore.addSelectedPostChangeListener(this._onChange); PostStore.addSelectedPostChangeListener(this._onChange);
PostStore.addChangeListener(this._onChangeAll); PostStore.addChangeListener(this._onChangeAll);
UserStore.addStatusesChangeListener(this._onTimeChange);
this.resize(); this.resize();
var self = this; var self = this;
$(window).resize(function(){ $(window).resize(function(){
@@ -289,11 +291,15 @@ module.exports = React.createClass({
}); });
}, },
componentDidUpdate: function() { componentDidUpdate: function() {
this.resize(); if(!this.wasForced){
this.resize();
wasForced = false
}
}, },
componentWillUnmount: function() { componentWillUnmount: function() {
PostStore.removeSelectedPostChangeListener(this._onChange); PostStore.removeSelectedPostChangeListener(this._onChange);
PostStore.removeChangeListener(this._onChangeAll); PostStore.removeChangeListener(this._onChangeAll);
UserStore.removeStatusesChangeListener(this._onTimeChange)
}, },
_onChange: function() { _onChange: function() {
if (this.isMounted()) { if (this.isMounted()) {
@@ -333,6 +339,14 @@ module.exports = React.createClass({
this.setState(getStateFromStores()); 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() { getInitialState: function() {
return getStateFromStores(); return getStateFromStores();
}, },
@@ -392,7 +406,7 @@ module.exports = React.createClass({
<RootPost post={root_post} commentCount={posts_array.length}/> <RootPost post={root_post} commentCount={posts_array.length}/>
<div className="post-right-comments-container"> <div className="post-right-comments-container">
{ posts_array.map(function(cpost) { { posts_array.map(function(cpost) {
return <CommentPost key={cpost.id} post={cpost} selected={ (cpost.id == selected_post.id) } /> return <CommentPost ref={cpost.id} key={cpost.id} post={cpost} selected={ (cpost.id == selected_post.id) } />
})} })}
</div> </div>
<div className="post-create__container"> <div className="post-create__container">