var ReactBootstrap = require('react-bootstrap') , Grid = ReactBootstrap.Grid , Col = ReactBootstrap.Col , Row = ReactBootstrap.Row , ListGroupItem = ReactBootstrap.ListGroupItem var React = require('react'); var SetIntervalMixin = require("../common/SetIntervalMixin.js"); var SafeStateChangeMixin = require('../common/SafeStateChangeMixin.js'); module.exports = Post = React.createClass({ mixins: [SetIntervalMixin,SafeStateChangeMixin], 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<18*60*60) {newTimeAgo=Math.round(secondsAgo/60/60)+"h"} else if (secondsAgo<26*24*60*60) {newTimeAgo=Math.round(secondsAgo/24/60/60)+"d"} else if (secondsAgo<9*30.5*24*60*60) {newTimeAgo=Math.round(secondsAgo/30.5/24/60/60)+"mo"} else {newTimeAgo=Math.round(secondsAgo/365/24/60/60)+"y"} this.setStateSafe({timeAgo: newTimeAgo}); }, 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){ if (avatar.getUrl()) { thisComponent.setStateSafe({avatar: avatar.getUrl()}); } }); Twister.getUser(this.props.post.username).doProfile(function(profile){ thisComponent.setStateSafe({fullname: profile.getField("fullname")}); }); if (this.props.post.isRetwist) { Twister.getUser(this.props.post.retwistingUser).doProfile(function(profile){ thisComponent.setStateSafe({retwistingUser: profile.getField("fullname")}); }); } this.updateTimeAgo(); this.setInterval(this.updateTimeAgo,60000); }, render: function() { var post = this.props.post; return ( {this.state.fullname}  {post.content} {this.state.timeAgo} {post.isRetwist &&  retwisted by {this.state.retwistingUser} } test ); } }); /*
{this.state.fullname} @{post.username} - {post.id}
{post.timestamp}
{post.content}

*/