2015-04-21 19:38:17 +02:00
|
|
|
|
|
|
|
|
|
var ReactBootstrap = require('react-bootstrap')
|
|
|
|
|
, Grid = ReactBootstrap.Grid
|
|
|
|
|
, Col = ReactBootstrap.Col
|
|
|
|
|
, Row = ReactBootstrap.Row
|
|
|
|
|
, ListGroupItem = ReactBootstrap.ListGroupItem
|
|
|
|
|
|
|
|
|
|
var React = require('react');
|
|
|
|
|
|
|
|
|
|
var SetIntervalMixin = require("./SetIntervalMixin.js");
|
2015-04-22 10:38:44 +02:00
|
|
|
|
var SafeStateChangeMixin = require('./SafeStateChangeMixin.js');
|
2015-04-21 19:38:17 +02:00
|
|
|
|
|
|
|
|
|
module.exports = Post = React.createClass({displayName: "Post",
|
2015-04-22 10:38:44 +02:00
|
|
|
|
mixins: [SetIntervalMixin,SafeStateChangeMixin],
|
2015-04-21 19:38:17 +02:00
|
|
|
|
getInitialState: function() {
|
|
|
|
|
return {
|
|
|
|
|
avatar: "img/genericPerson.png",
|
|
|
|
|
fullname: "",
|
|
|
|
|
retwistingUser: this.props.post.retwistingUser,
|
|
|
|
|
timeAgo: ""
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
updateTimeAgo: function() {
|
|
|
|
|
var secondsAgo = Date.now()/1000-this.props.post.timestamp;
|
|
|
|
|
|
|
|
|
|
var newTimeAgo = "";
|
|
|
|
|
|
|
|
|
|
if (secondsAgo<45) {newTimeAgo="1m"}
|
|
|
|
|
else if (secondsAgo<45*60) {newTimeAgo=Math.round(secondsAgo/60)+"m"}
|
|
|
|
|
else if (secondsAgo<45*60*60) {newTimeAgo=Math.round(secondsAgo/60/60)+"h"}
|
|
|
|
|
else if (secondsAgo<60*60*60*18) {newTimeAgo=Math.round(secondsAgo/60/60/60)+"d"}
|
|
|
|
|
|
2015-04-22 10:38:44 +02:00
|
|
|
|
this.setStateSafe({timeAgo: newTimeAgo});
|
2015-04-21 19:38:17 +02:00
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
componentDidMount: function () {
|
|
|
|
|
var thisComponent = this;
|
|
|
|
|
|
|
|
|
|
//console.log(this.props.post.username+":post"+this.props.post.id);
|
|
|
|
|
Twister.getUser(this.props.post.username).doAvatar(function(avatar){
|
2015-04-22 10:38:44 +02:00
|
|
|
|
thisComponent.setStateSafe({avatar: avatar.getUrl()});
|
2015-04-21 19:38:17 +02:00
|
|
|
|
});
|
|
|
|
|
Twister.getUser(this.props.post.username).doProfile(function(profile){
|
2015-04-22 10:38:44 +02:00
|
|
|
|
thisComponent.setStateSafe({fullname: profile.getField("fullname")});
|
2015-04-21 19:38:17 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (this.props.post.isRetwist) {
|
|
|
|
|
|
|
|
|
|
Twister.getUser(this.props.post.retwistingUser).doProfile(function(profile){
|
2015-04-22 10:38:44 +02:00
|
|
|
|
thisComponent.setStateSafe({retwistingUser: profile.getField("fullname")});
|
2015-04-21 19:38:17 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.updateTimeAgo();
|
|
|
|
|
|
|
|
|
|
this.setInterval(this.updateTimeAgo,60000);
|
|
|
|
|
},
|
|
|
|
|
render: function() {
|
|
|
|
|
var post = this.props.post;
|
|
|
|
|
return (
|
2015-04-22 10:38:44 +02:00
|
|
|
|
React.createElement(ListGroupItem, {fill: true},
|
2015-04-21 19:38:17 +02:00
|
|
|
|
React.createElement(Grid, {fill: true},
|
|
|
|
|
React.createElement(Row, null,
|
2015-04-22 10:38:44 +02:00
|
|
|
|
React.createElement(Col, {xs: 2, className: "fullytight"}, React.createElement("img", {className: "img-responsive", src: this.state.avatar})),
|
2015-04-21 19:38:17 +02:00
|
|
|
|
React.createElement(Col, {xs: 9},
|
|
|
|
|
React.createElement("strong", null, this.state.fullname), " ",
|
|
|
|
|
post.content
|
|
|
|
|
),
|
2015-04-22 10:38:44 +02:00
|
|
|
|
React.createElement(Col, {xs: 1, className: "fullytight"}, React.createElement("p", {className: "text-right"}, this.state.timeAgo))
|
2015-04-21 19:38:17 +02:00
|
|
|
|
),
|
|
|
|
|
React.createElement(Row, null,
|
2015-04-22 10:38:44 +02:00
|
|
|
|
React.createElement(Col, {xs: 6},
|
2015-04-21 19:38:17 +02:00
|
|
|
|
post.isRetwist && React.createElement("small", null, React.createElement("span", {className: "glyphicon glyphicon-retweet", "aria-hidden": "true"}), " ", React.createElement("em", null, " retwisted by ", this.state.retwistingUser))
|
|
|
|
|
|
|
|
|
|
),
|
2015-04-22 10:38:44 +02:00
|
|
|
|
React.createElement(Col, {xs: 6}, React.createElement("p", {className: "text-right"}, React.createElement("small", null, React.createElement("em", null, "test"))))
|
2015-04-21 19:38:17 +02:00
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
<div className="post-avatar">
|
|
|
|
|
<img src={this.state.avatar}/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="post-bulk">
|
|
|
|
|
<div className="post-username">
|
|
|
|
|
<span className="post-fullname">{this.state.fullname} </span>
|
|
|
|
|
@{post.username} - {post.id}
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
<div className="post-timestamp">{post.timestamp}</div>
|
|
|
|
|
<div className="post-content">{post.content}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<hr/>
|
|
|
|
|
|
|
|
|
|
*/
|