diff options
Diffstat (limited to 'app/javascript/components/Home.jsx')
| -rw-r--r-- | app/javascript/components/Home.jsx | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/app/javascript/components/Home.jsx b/app/javascript/components/Home.jsx index efe3cd5..6ead779 100644 --- a/app/javascript/components/Home.jsx +++ b/app/javascript/components/Home.jsx @@ -1,8 +1,27 @@ -import React from "react"; +import React, { } from "react"; import { Link } from "react-router-dom"; -export default () => ( - <div className="vh-100 primary-color d-flex align-items-center justify-content-center"> +//export default () => ( +export default function Home () { + var handleSubmit = (e) => { + e.preventDefault() //stops submit from happening + + const formData = new FormData() + formData.append('game[title]', e.target.title.value) + formData.append('game[game_file]', e.target.game_file.files[0], e.target.game_file.value) + +for (var pair of formData.entries()) { + console.log(pair[0] + ', ' + pair[1]) +}; + + fetch('http://127.0.0.1:3000/api/v1/games', { + method: 'post', + body: formData, + }); + } + return( + <> + <div className="vw-100 vh-100 primary-color d-flex align-items-center justify-content-center"> <div className="jumbotron jumbotron-fluid bg-transparent"> <div className="container secondary-color"> <h1 className="display-4">Games!</h1> @@ -17,14 +36,17 @@ export default () => ( > View Games </Link> - <Link - to="/blogs" - className="btn btn-lg custom-button" - role="button" - > - View Blogs - </Link> </div> + <form onSubmit={handleSubmit} action="/upload" method="post"> + <label>Title</label> + <input type="text" name="title" /> + <label>File</label> + <input type="file" name="game_file" /> + + <button type="submit">submit</button> + </form> </div> </div> + </> ); +}; |
