p5.js-web-editor/client/modules/IDE/components/Timer.jsx
Cassie Tarakajian e87390adb9 update eslint to latest version, fix lots of linting errors (#308)
* update eslint and dependencies, fix linting errors that can be fixed with --fix

* fix lots of linting errors

* update eslintrc, fix some linting errors

* fix all server side linting errors, untested

* fix errors that fixing linting errors had caused

* fix client side eslint errors

* fix client side linting errors

* fix refs lint errors

* fix more linting errors

* update eslint and dependencies, fix linting errors that can be fixed with --fix

* fix lots of linting errors

* update eslintrc, fix some linting errors

* fix all server side linting errors, untested

* fix errors that fixing linting errors had caused

* fix client side eslint errors

* fix client side linting errors

* fix refs lint errors

* fix more linting errors

* fix some accessibility linting errors

* fix a lot of linting errors

* fix a billion more linting errors

* hopefully fix all linting errors, still need to test

* fix bugs that fixing linting had caused
2017-02-22 14:29:35 -05:00

56 lines
1.4 KiB
JavaScript

import React, { PropTypes } from 'react';
import moment from 'moment';
import classNames from 'classnames';
class Timer extends React.Component {
constructor(props) {
super(props);
this.showSavedTime = this.showSavedTime.bind(this);
}
componentDidMount() {
this.interval = setInterval(() => this.forceUpdate(), 10000);
}
componentWillUnmount() {
if (this.interval) {
clearInterval(this.interval);
}
}
showSavedTime() {
if (Math.abs(moment().diff(this.props.projectSavedTime)) < 10000) {
return 'Saved: just now';
} else if (Math.abs(moment().diff(this.props.projectSavedTime)) < 20000) {
return 'Saved: 15 seconds ago';
} else if (Math.abs(moment().diff(this.props.projectSavedTime)) < 30000) {
return 'Saved: 25 seconds ago';
} else if (Math.abs(moment().diff(this.props.projectSavedTime)) < 46000) {
return 'Saved: 35 seconds ago';
}
return `Saved: ${moment(this.props.projectSavedTime).fromNow()}`;
}
render() {
const timerClass = classNames({
'timer__saved-time': true,
'timer__saved-time--notOwner': !this.props.isUserOwner
});
return (
<span className={timerClass}>
{this.props.projectSavedTime !== '' ? this.showSavedTime() : null}
</span>
);
}
}
Timer.propTypes = {
projectSavedTime: PropTypes.string.isRequired,
isUserOwner: PropTypes.bool
};
Timer.defaultProps = {
isUserOwner: false
};
export default Timer;