Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from "react";
  2. import logo from "./logo.png";
  3. import { Table } from "reactstrap";
  4. import { Button } from "reactstrap";
  5. import { Form, FormGroup, Label, Input, FormText } from "reactstrap";
  6.  
  7. import axios from "axios";
  8.  
  9. import "./App.css";
  10.  
  11. class App extends React.Component {
  12.   state = {
  13.     message: "",
  14.     x: null,
  15.     y: null,
  16.     direction: null
  17.   };
  18.  
  19.   handleSubmit(e) {
  20.     console.log("Submitted");
  21.     e.preventDefault();
  22.     axios({
  23.       method: "POST",
  24.       url: "http://localhost:8080/send",
  25.       data: this.state.message
  26.     }).then(response => {
  27.       if (response.data.status === "success") {
  28.         alert("Script Submitted.");
  29.         this.resetForm();
  30.       } else if (response.data.status === "fail") {
  31.         alert("Script failed");
  32.       }
  33.     });
  34.   }
  35.  
  36.   resetForm() {
  37.     this.setState({ message: "" });
  38.   }
  39.  
  40.   render() {
  41.     return (
  42.       <div className="App">
  43.         <header className="App-header">
  44.           <img src={logo} className="App-logo" alt="logo" />
  45.           <h1 className="App-title">Welcome to robot controller</h1>
  46.         </header>
  47.         <form
  48.           id="contact-form"
  49.           onSubmit={this.handleSubmit.bind(this)}
  50.           method="POST"
  51.         >
  52.           <div className="form-group">
  53.             <label htmlFor="message"></label>
  54.             <textarea
  55.               className="form-control"
  56.               rows="5"
  57.               id="message"
  58.               value={this.state.message}
  59.               onChange={this.onMessageChange.bind(this)}
  60.             />
  61.           </div>
  62.           <Button type="submit" className="btn-primary" color="primary">
  63.             Submit
  64.           </Button>
  65.         </form>
  66.         <table>
  67.           <tbody>
  68.             {Array.from({ length: 5 }, _ => (
  69.               <tr>
  70.                 {Array.from({ length: 5 }, _ => (
  71.                   <Cell />
  72.                 ))}
  73.               </tr>
  74.             ))}
  75.           </tbody>
  76.         </table>
  77.       </div>
  78.     );
  79.   }
  80.  
  81.   onMessageChange(event) {
  82.     this.setState({ message: event.target.value });
  83.   }
  84. }
  85.  
  86. class Cell extends React.Component {
  87.   render() {
  88.     return <td className="cell"></td>;
  89.   }
  90. }
  91.  
  92. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement