summaryrefslogtreecommitdiffhomepage
path: root/app/javascript/components/Home.jsx
blob: 6ead7799e8f9c9e98540878cddd6aefbc77a50b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, { } from "react";
import { Link } from "react-router-dom";

//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>
        <p className="lead">
			All the games I have worked on that run on the web!
        </p>
        <hr className="my-4" />
        <Link
          to="/games"
          className="btn btn-lg custom-button"
          role="button"
        >
          View Games
        </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>
	  </>
);
};