LogoSpin Component implements

This commit is contained in:
Francesco Esposito 2019-03-21 12:00:36 +01:00
parent 637cc9b467
commit b47e9f0f2d
3 changed files with 87 additions and 52 deletions

View File

@ -0,0 +1,23 @@
.App-logo {
height: 25vmin;
pointer-events: none;
filter: drop-shadow(0 0 0.50rem #f8ff9c);
align-items: center;
justify-content: center;
text-align: center;
}
.App-logo-rotation {
animation: App-logo-spin infinite 5s linear;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

View File

@ -0,0 +1,23 @@
import React, { Component } from 'react';
import logo from '../logo.svg';
import './LogoSpin.css';
class LogoSpin extends Component {
constructor(props) {
super(props);
this.defaultClassName = 'App-logo-rotation';
}
render() {
return (
<img
className={`App-logo ${this.props.isStarted ? this.defaultClassName: ''}`}
src={logo}
alt="Tomato"
></img>
)
}
}
export default LogoSpin;

View File

@ -2,20 +2,17 @@ import React, { Component } from 'react';
import { Container, Row, Col } from 'reactstrap'; import { Container, Row, Col } from 'reactstrap';
import Notification from 'react-web-notification'; import Notification from 'react-web-notification';
import ButtonBox from './ButtonBox'; import ButtonBox from './ButtonBox';
import LogoSpin from './LogoSpin';
import './Timer.css'; import './Timer.css';
import logo from '../logo.svg';
import sound from '../sound.mp3'; import sound from '../sound.mp3';
class Timer extends Component { class Timer extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.seconds = 1500; this.state = {
this.logoSpingCSS = 'App-logo-rotation'; seconds: 1500,
this.state = {
seconds: this.seconds,
started: false, started: false,
logoSpin: '',
ignore: true, ignore: true,
title: '' title: ''
}; };
@ -30,9 +27,9 @@ class Timer extends Component {
this.handleNotificationOnShow = this.handleNotificationOnShow.bind(this); this.handleNotificationOnShow = this.handleNotificationOnShow.bind(this);
this.playSound = this.playSound.bind(this); this.playSound = this.playSound.bind(this);
} }
formatMinute(s){ formatMinute(s) {
return ( s - ( s%=60 )) / 60 + ( 9 < s ?':':':0') +s; return (s - (s %= 60)) / 60 + (9 < s ? ':' : ':0') + s;
} }
@ -54,7 +51,7 @@ class Timer extends Component {
}); });
} }
handleNotificationOnError(e, tag){ handleNotificationOnError(e, tag) {
console.log(e, 'Notification error tag:' + tag); console.log(e, 'Notification error tag:' + tag);
} }
@ -75,7 +72,7 @@ class Timer extends Component {
tag: tag, tag: tag,
body: body, body: body,
lang: 'en', lang: 'en',
sound: {sound} sound: { sound }
}; };
this.setState({ this.setState({
@ -84,14 +81,14 @@ class Timer extends Component {
}); });
} }
playSound(){ playSound() {
document.getElementById('sound').play(); document.getElementById('sound').play();
} }
tick() { tick() {
this.setState(state => ({ this.setState(state => ({
seconds: state.seconds -1 seconds: state.seconds - 1
})); }));
if (this.state.seconds <= 0) { if (this.state.seconds <= 0) {
@ -102,28 +99,22 @@ class Timer extends Component {
} }
startTimer() { startTimer() {
this.setState({ this.setState({
started: true, started: true
logoSpin: this.logoSpingCSS
}); });
this.interval = setInterval(() => this.tick(), 1000); this.interval = setInterval(() => this.tick(), 1000);
} }
stopTimer() { stopTimer() {
this.setState({ this.setState({
started: false, started: false
logoSpin: null });
});
clearInterval(this.interval); clearInterval(this.interval);
} }
resetTimer() { resetTimer() {
this.stopTimer(); this.stopTimer();
this.setState({ seconds: this.seconds}); this.setState({ seconds: 1500 });
}
isStarted() {
return this.state.started;
} }
render() { render() {
@ -132,31 +123,29 @@ class Timer extends Component {
<Container> <Container>
<Row> <Row>
<Col> <Col>
<img <LogoSpin
className={`App-logo ${this.state.logoSpin}`} isStarted={this.state.started}
src={logo} />
alt="Tomato"
></img>
</Col> </Col>
</Row> </Row>
<Row> <Row>
<Col> <Col>
<p <p
className="timer" className="timer"
> >
{this.formatMinute(this.state.seconds)} {this.formatMinute(this.state.seconds)}
</p> </p>
</Col> </Col>
</Row> </Row>
<Row> <Row>
<Col> <Col>
<ButtonBox <ButtonBox
startTimer = {this.startTimer} startTimer={this.startTimer}
stopTimer = {this.stopTimer} stopTimer={this.stopTimer}
isStarted = {this.state.started} isStarted={this.state.started}
resetTimer = {this.resetTimer} resetTimer={this.resetTimer}
/> />
</Col> </Col>
</Row> </Row>
@ -164,14 +153,14 @@ class Timer extends Component {
<Notification <Notification
ignore={this.state.ignore} ignore={this.state.ignore}
onPermissionGranted = {this.handlePermissionGranted} onPermissionGranted={this.handlePermissionGranted}
onPermissionDenied = {this.handlePermissionDenied} onPermissionDenied={this.handlePermissionDenied}
notSupported = {this.handleNotSupported} notSupported={this.handleNotSupported}
onError = {this.onError} onError={this.onError}
timeout = {5000} timeout={5000}
title = {this.state.title} title={this.state.title}
options = {this.state.options} options={this.state.options}
onShow = {this.handleNotificationOnShow} onShow={this.handleNotificationOnShow}
> >
</Notification> </Notification>
@ -179,7 +168,7 @@ class Timer extends Component {
<source src={sound} type='audio/mpeg' /> <source src={sound} type='audio/mpeg' />
<embed hidden src={sound} /> <embed hidden src={sound} />
</audio> </audio>
</div> </div>
); );
} }