Advertisement
Qpel

kauliukas 4prktk

Nov 19th, 2019
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app:
  2.  
  3. import React, {Component} from 'react'
  4.  
  5. class App extends Component {
  6.     constructor(props) {
  7.         super(props)
  8.         this.inputSelect = React.createRef()
  9.         this.onHandleCurrentCoordinate = this.onHandleCurrentCoordinate.bind(this)
  10.  
  11.         this.Kauliukas = this.Kauliukas.bind(this);
  12.        
  13.         this._diceNumber = this._diceNumber.bind(this)
  14.  
  15.         this.state = {
  16.             isLoaded: false,
  17.             //shipLocation: [x: 0, y: 0],
  18.             value: '',
  19.             coordinates: [],
  20.             random: 3
  21.     }
  22. }
  23.  
  24.  
  25. Kauliukas() {
  26.     const rand = Math.floor(Math.random() * 6) + 1 ;
  27.     this.setState({ random:  rand });
  28.   }
  29.  
  30.   Atvaizduoja() {
  31.     let products = []
  32.     for (let i = 0; i < this.state.random; i++){
  33.         console.log(i);
  34.       products.push( <div className="grid-item"></div> )
  35.     }
  36.     return products
  37.   }
  38.  
  39. _diceNumber(){
  40.     return  Math.floor(Math.random() * 6);
  41. }
  42. onHandleCurrentCoordinate() {
  43.     const coordinateId = this.inputSelect.current.value//passiima values kelintas
  44.     const data = {coordinateId: coordinateId}
  45.     fetch("http://localhost:3000/api/coordinate", {
  46.         method: 'POST',
  47.         headers: {"Content-type": "application/json" },
  48.         body: JSON.stringify(data)
  49.     })
  50.     .then(res => res.json())
  51.     .then(result => {
  52.         this.setState({
  53.             isLoaded: false,
  54.             currentCoordinate: result
  55.         })
  56.     })
  57.     .catch(e => console.log(e))
  58. }
  59.  
  60.  
  61.  
  62.     render() {
  63.         const currentCoordinate  =this.state
  64.        
  65.         return (
  66.             <div>
  67.                
  68.                 <button onClick={this.Kauliukas.bind(this) }>Kauliukas</button>
  69.                 <div>Iskrito: {this.state.random} </div>
  70.                 <div className="grid-container">
  71.                 {this.Atvaizduoja()}
  72.                 </div>
  73.             </div>
  74.            
  75.            
  76.         )
  77.     }
  78.    
  79. }
  80.  
  81. export default App
  82.  
  83.  
  84.  
  85. style.css:
  86.  
  87. * {
  88.   font-family: sans-serif;
  89.   margin: 0;
  90. }
  91. button {
  92.   height: 40px;
  93.   width: 200px;
  94.   margin: 10px;
  95. }
  96. .warning {
  97.   background-color: red;
  98.   text-align: center;
  99.   width: 100%;
  100.   padding: 10px;
  101.  
  102.   font-size: 14pt;
  103.   color: white;
  104. }
  105. .hide{
  106.     width: 30px;
  107.     height: 30px;
  108.     float: right;
  109. }
  110.  
  111. .grid-container {
  112.   display: grid;
  113.   grid-template-columns: 100px 100px;
  114.   padding: 15px;
  115. }
  116.  
  117. .grid-item {
  118.   background-color: rgba(115, 115, 115, 0.8);
  119.   border: 1px solid rgba(89, 89, 89, 0.8);
  120.   padding: 40px;
  121.   border-radius: 50px;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement