mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-03-12 21:48:39 +01:00
clocks now updates itself! woo
This commit is contained in:
parent
ae898444ad
commit
7d4e6b419b
@ -3,21 +3,31 @@ var Icon = require('icon.jsx')
|
|||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
getInitialState: function(){
|
getInitialState: function(){
|
||||||
return { moment: false }
|
return { moment: false, text: '...' }
|
||||||
},
|
},
|
||||||
componentDidMount: function(){
|
componentDidMount: function(){
|
||||||
require.ensure(['moment'],_ => {
|
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(){
|
getDate: function(){
|
||||||
if(this.props.date){
|
if(this.state.moment)
|
||||||
if(this.state.moment)
|
return this.state.text
|
||||||
return this.state.moment.unix(this.props.date).fromNow()
|
else
|
||||||
else return <Icon name="refresh" className="fa-spin" />
|
return <Icon name="refresh" className="fa-spin" />
|
||||||
} else {
|
|
||||||
return 'Unknown Date'
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
render: function(){
|
render: function(){
|
||||||
return <div className="clock"><Icon name="clock-o" className={this.props.className} /> {this.getDate()}</div>
|
return <div className="clock"><Icon name="clock-o" className={this.props.className} /> {this.getDate()}</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user