From 519568969b9ff3a47e595073a40fef099586e3c9 Mon Sep 17 00:00:00 2001 From: Tradam Date: Thu, 16 May 2024 12:18:04 -0400 Subject: rendering an uploaded HTML file --- app/javascript/components/Games.jsx | 71 ++++++++++++++++++++++++++++++++++++ app/javascript/components/Home.jsx | 19 ---------- app/javascript/components/Layout.jsx | 12 +++--- 3 files changed, 77 insertions(+), 25 deletions(-) create mode 100644 app/javascript/components/Games.jsx (limited to 'app/javascript/components') diff --git a/app/javascript/components/Games.jsx b/app/javascript/components/Games.jsx new file mode 100644 index 0000000..adf9f2d --- /dev/null +++ b/app/javascript/components/Games.jsx @@ -0,0 +1,71 @@ +import React, { useState, useEffect } from "react"; +//import { Link } from "react-router-dom"; +import GameCard from "./GameCard"; + +//export default () => ( +export default function Games () { + const [games, setGames] = useState([]); + useEffect(() => { + const url = "/api/v1/games/index"; + fetch(url).then((response) => { + if (response.ok) { + return response.json(); + } + throw new Error("Network response was not ok."); + }).then((response) => setGames(response)).catch(() => navigate("/")); + }, []); + const allGames = games.map((games, index) => ( +
{ blog }
+ )); + 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( + <> +
+
+
Games
+
+
+
+
+
+ + +
+
+ + +
+ +
+
+
+
+ { allGames } +
+ + + + + + +
+
+
+ + ); +}; diff --git a/app/javascript/components/Home.jsx b/app/javascript/components/Home.jsx index b67571c..5f79834 100644 --- a/app/javascript/components/Home.jsx +++ b/app/javascript/components/Home.jsx @@ -33,27 +33,8 @@ export default function Home () { Ea optio vitae culpa voluptatem consectetur. Ab quisquam sed ipsum. Perspiciatis minus odit quas qui consequuntur dicta reiciendis a. Nihil minima sed aliquam.


-
-
- -
-
- -
- -
- - - -
- - - - - -
diff --git a/app/javascript/components/Layout.jsx b/app/javascript/components/Layout.jsx index 01ec055..30d1086 100644 --- a/app/javascript/components/Layout.jsx +++ b/app/javascript/components/Layout.jsx @@ -14,9 +14,9 @@ export default function Layout ({userData}) { userData.name ?
Logged in as:
{userData.name}
: Login with Github }
Adam Malczewski
-
-- cgit v1.2.3