diff --git a/webapp/components/clock.jsx b/webapp/components/clock.jsx index 10136d9..798ba39 100644 --- a/webapp/components/clock.jsx +++ b/webapp/components/clock.jsx @@ -3,21 +3,31 @@ var Icon = require('icon.jsx') module.exports = React.createClass({ getInitialState: function(){ - return { moment: false } + return { moment: false, text: '...' } }, componentDidMount: function(){ require.ensure(['moment'],_ => { - if(this.isMounted()) this.setState({ moment: require('moment') }) + if(this.isMounted()){ + var moment = require('moment') + this.setState({ + moment: moment, + interval: setInterval(this.upDate,60*1000), + text: moment.unix(this.props.date).fromNow() + }) + } }) }, + upDate: function(){ + if(this.isMounted()) + this.setState({ text: this.state.moment.unix(this.props.date).fromNow() }) + else + clearInterval(this.state.interval) + }, getDate: function(){ - if(this.props.date){ - if(this.state.moment) - return this.state.moment.unix(this.props.date).fromNow() - else return - } else { - return 'Unknown Date' - } + if(this.state.moment) + return this.state.text + else + return }, render: function(){ return
{this.getDate()}