Carapal react mockup

This is really just a mock up written in React to try different
components. It could become scaffolding to build a prototype, or not.
This commit is contained in:
Maxime Beauchemin
2016-05-21 22:07:37 -07:00
parent 23a5463208
commit 07a6a0a630
29 changed files with 2174 additions and 38 deletions

View File

@@ -0,0 +1,62 @@
import React from 'react';
import moment from 'moment';
class Timer extends React.Component {
constructor(props) {
super(props);
this.state = {
clockStr: '',
};
}
componentWillMount() {
this.startTimer();
}
componentWillUnmount() {
this.stopTimer();
}
startTimer() {
if (!(this.timer)) {
this.timer = setInterval(this.stopwatch.bind(this), 30);
}
}
stopTimer() {
clearInterval(this.timer);
this.timer = null;
}
stopwatch() {
if (this.props && this.props.query) {
let fromDttm = this.props.query.endDttm || new Date();
fromDttm = moment(fromDttm);
let duration = fromDttm - moment(this.props.query.startDttm).valueOf();
duration = moment.utc(duration);
const clockStr = duration.format('HH:mm:ss.SS');
this.setState({ clockStr });
if (this.props.query.state !== 'running') {
this.stopTimer();
}
}
}
render() {
if (this.props.query && this.props.query.state === 'running') {
this.startTimer();
}
let timerSpan = null;
if (this.props && this.props.query) {
timerSpan = (
<span className={'label label-warning inlineBlock m-r-5 ' + this.props.query.state}>
{this.state.clockStr}
</span>
);
}
return timerSpan;
}
}
Timer.propTypes = {
query: React.PropTypes.object,
};
Timer.defaultProps = {
query: null,
};
export default Timer;