Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app:
- import React, {Component} from 'react'
- //import { start } from 'repl'
- class App extends Component {
- constructor(props) {
- super(props)
- this.inputSelect = React.createRef()
- this.onHandleCurrentCoordinate = this.onHandleCurrentCoordinate.bind(this)
- this.state = {
- isLoaded: false,
- //shipLocation: [x: 0, y: 0],
- value: '',
- coordinates: []
- }
- }
- componentDidMount(){
- const result = {
- actionType: 'start'
- }
- fetch('http://localhost:3000/api/action', {
- method: 'POST',
- body: JSON.stringify(result)
- })
- .then(res => res.json())
- .then(result => {
- this.setState({
- currentCoordinate: result
- })
- })
- }
- _onHandleAction(actionType, bonus = {}){
- const result = {
- actionType,
- bonus
- }
- fetch('http://localhost:3000/api/action', {
- method: 'POST',
- body: JSON.stringify(result)
- })
- .then(res => res.json())
- .then(result => {
- this.setState({
- currentCoordinate: result
- })
- })
- }
- onHandleCurrentCoordinate() {
- const coordinateId = this.inputSelect.current.value//passiima values kelintas
- const data = {coordinateId: coordinateId}
- fetch("http://localhost:3000/api/coordinate", {
- method: 'POST',
- headers: {"Content-type": "application/json" },
- body: JSON.stringify(data)
- })
- .then(res => res.json())
- .then(result => {
- this.setState({
- isLoaded: false,
- currentCoordinate: result
- })
- })
- .catch(e => console.log(e))
- }
- render() {
- const {currentCoordinate} =this.state
- return (
- <div className="img">
- <div>
- <p></p>
- <p></p>
- <button onClick={e => {this._onHandleAction('dice')} }>Kauliukas</button>
- <div className="laivas"> </div>
- <div className="text"> Žemėlapis </div> </div>
- </div>
- )
- }
- }
- export default App
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement