Created
April 24, 2019 07:52
-
-
Save gearmobile/a3ba7181aa2a3e9b44b4676aee7cc315 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Site extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
offices: [] | |
}; | |
this.getOffices = this.getOffices.bind(this); | |
} | |
componentDidMount() { | |
this.getOffices(); | |
} | |
render() { | |
return ( | |
<div> | |
<header className="info"> | |
<h1>Одна большая компания</h1> | |
<p>Будем рады видеть вас в одном из наших офисов</p> | |
</header> | |
<main className="map map-container"> | |
<Map points={this.state.offices} numberToShowMap={5} /> | |
</main> | |
<button className="button" onClick={this.getOffices}> | |
Обновить местоположение офисов | |
</button> | |
</div> | |
); | |
} | |
getOffices() { | |
this.setState({ | |
offices: new Array(random(1, 15, false)) | |
.fill(0) | |
.map(() => ({ lon: random(-180, 180), lat: random(-90, 90) })) | |
}); | |
} | |
} | |
const random = (lower = 0, upper = 1, floating = true) => | |
floating | |
? Math.min(lower + Math.random() * (upper - lower), upper) | |
: lower + Math.floor(Math.random() * (upper - lower + 1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment