front/src/components/App.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-11-18 15:47:54 +01:00
import React, { Component } from 'react';
2018-11-18 19:03:01 +01:00
import Header from './Header';
2018-11-18 15:47:54 +01:00
import {
BrowserRouter as Router, Route,
Switch,
} from 'react-router-dom';
2018-11-18 19:03:01 +01:00
import Map from './Map';
import Home from './Home';
import Vegetables from './Vegetables';
2018-11-18 15:47:54 +01:00
class App extends Component {
constructor(props) {
super(props)
this.state = {
background: 1
}
this.changeBackground.bind = this.changeBackground();
}
changeBackground = () => {
setInterval(() => {
let currentBackground = this.state.background;
document.body.style.background = `url('/background/${currentBackground}.jpg') no-repeat fixed`;
document.body.style.backgroundSize = 'cover';
document.body.style.backgroundPosition = 'center center';
if (currentBackground === 4) {
currentBackground = 0
}
this.setState({
background: currentBackground + 1
})
}, 10000);
}
render() {
return (
<div className="App">
<Header></Header>
<Router>
<Switch>
2018-11-18 19:03:01 +01:00
<Route exact path="/" component={Home} />
<Route exact path="/carte" component={Map} />
2018-11-18 15:47:54 +01:00
<Route exact path="/vegetaux" component={Vegetables} />
<Route exact path="/vegetaux/:id-:slug" component={Vegetables} />
</Switch>
</Router>
</div>
);
}
}
export default App;