2015-11-23 18:38:21 +01:00
|
|
|
var React = require('react')
|
|
|
|
var Icon = require('icon.jsx')
|
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
getInitialState: function(){
|
2015-11-23 18:55:28 +01:00
|
|
|
return { moment: false, text: '...' }
|
2015-11-23 18:38:21 +01:00
|
|
|
},
|
|
|
|
componentDidMount: function(){
|
|
|
|
require.ensure(['moment'],_ => {
|
2015-11-23 18:55:28 +01:00
|
|
|
if(this.isMounted()){
|
|
|
|
var moment = require('moment')
|
|
|
|
this.setState({
|
|
|
|
moment: moment,
|
|
|
|
interval: setInterval(this.upDate,60*1000),
|
|
|
|
text: moment.unix(this.props.date).fromNow()
|
|
|
|
})
|
|
|
|
}
|
2015-11-23 18:38:21 +01:00
|
|
|
})
|
|
|
|
},
|
2015-11-23 18:55:28 +01:00
|
|
|
upDate: function(){
|
|
|
|
if(this.isMounted())
|
|
|
|
this.setState({ text: this.state.moment.unix(this.props.date).fromNow() })
|
|
|
|
else
|
|
|
|
clearInterval(this.state.interval)
|
|
|
|
},
|
2015-11-23 18:38:21 +01:00
|
|
|
getDate: function(){
|
2015-11-23 18:55:28 +01:00
|
|
|
if(this.state.moment)
|
|
|
|
return this.state.text
|
|
|
|
else
|
|
|
|
return <Icon name="refresh" className="fa-spin" />
|
2015-11-23 18:38:21 +01:00
|
|
|
},
|
|
|
|
render: function(){
|
2015-11-26 19:04:47 +01:00
|
|
|
return <div className="inline"><Icon name="clock-o" className={this.props.className} /> {this.getDate()}</div>
|
2015-11-23 18:38:21 +01:00
|
|
|
}
|
|
|
|
})
|