diff options
| -rw-r--r-- | app/controllers/api/v1/games_controller.rb | 10 | ||||
| -rw-r--r-- | app/javascript/components/Games.jsx | 71 | ||||
| -rw-r--r-- | app/javascript/components/Home.jsx | 19 | ||||
| -rw-r--r-- | app/javascript/components/Layout.jsx | 12 | ||||
| -rw-r--r-- | app/javascript/routes/index.jsx | 2 | ||||
| -rw-r--r-- | config/routes.rb | 4 |
6 files changed, 89 insertions, 29 deletions
diff --git a/app/controllers/api/v1/games_controller.rb b/app/controllers/api/v1/games_controller.rb index 073eec9..75d08a9 100644 --- a/app/controllers/api/v1/games_controller.rb +++ b/app/controllers/api/v1/games_controller.rb @@ -1,18 +1,24 @@ class Api::V1::GamesController < ApplicationController skip_before_action :verify_authenticity_token def create - puts request.methods.sort @game = Game.new(games_params) if @game.save + pp @game render json: @game, status: :created else render json: @game.errors, status: :unprocessable_entity end end + def index + game = Game.all.order(created_at: :desc) + #render json: game + render html: Game.first.game_file.download.html_safe + end + private def games_params - params.require(:game).permit(:title, :game_file) + params.require(:game).permit(:title, game_files:) end end 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) => ( + <div>{ blog }</div> + )); + 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> + <div className="flex flex-col gap-16 max-w-6xl shrink"> + <div className="title font-bold text-6xl font-title">Games</div> + <div className=""> + <div className="jumbotron jumbotron-fluid bg-transparent"> + <div className="container secondary-color"> + <form onSubmit={handleSubmit} action="/upload" method="post" className="flex flex-col gap-4"> + <div> + <label>Title</label> + <input type="text" name="title" /> + </div> + <div> + <label>File</label> + <input type="file" name="game_file" /> + </div> + <button type="submit" className="w-32 bg-stone-900 text-stone-50 rounded">submit</button> + </form> + </div> + </div> + </div> + { allGames } + <div className="flex flex-row flex-wrap gap-20 justify-around"> + <GameCard /> + <GameCard /> + <GameCard /> + <GameCard /> + <GameCard /> + <GameCard /> + </div> + </div> + </div> + </> + ); +}; 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. </p> <hr className="my-4" /> - <form onSubmit={handleSubmit} action="/upload" method="post" className="flex flex-col gap-4"> - <div> - <label>Title</label> - <input type="text" name="title" /> </div> - <div> - <label>File</label> - <input type="file" name="game_file" /> </div> - <button type="submit" className="w-32 bg-stone-900 text-stone-50 rounded">submit</button> - </form> - </div> - </div> - </div> - <div className="flex flex-row flex-wrap gap-20 justify-around"> - <GameCard /> - <GameCard /> - <GameCard /> - <GameCard /> - <GameCard /> - <GameCard /> </div> </div> </div> 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 ? <div className="flex items-end gap-2 pb-2"> <div className="text-xs"> Logged in as: </div> <div>{userData.name}</div> </div> : <a href="https://github.com/login/oauth/authorize?client_id=74468ad0847e527262d9" className="pb-2"> Login with Github </a> } <div className="text-3xl py-10 text-center font-title">Adam Malczewski</div> <div className="flex flex-col items-center gap-1 w-full"> - <Button link={ <Link to="/" className="text-stone-50 bg-transparent" role="button">About Me</Link> }/> - <Button link={ <Link to="/blogs" className="text-stone-50 bg-transparent" role="button">Blog</Link> }/> - <Button link={ <Link to="/games" className="text-stone-50 bg-transparent" role="button">Games</Link> }/> + <Button link={ <Link to="/" className="absolute flex top-0 left-0 w-36 h-16 text-stone-50 bg-transparent justify-center items-center" role="button"><div className="h-min">About Me</div></Link> }/> + <Button link={ <Link to="/blogs" className="absolute flex top-0 left-0 w-36 h-16 text-stone-50 bg-transparent justify-center items-center" role="button"><div className="h-min">Blog</div></Link> }/> + <Button link={ <Link to="/games" className="absolute flex top-0 left-0 w-36 h-16 text-stone-50 bg-transparent justify-center items-center" role="button"><div className="h-min">Games</div></Link> }/> <Button link={ <div className="text-stone-50 bg-transparent w-36 h-16 flex justify-center items-center"> <a id="contact" href="mailto:[email protected]" className="w-36 h-16 relative text-center whitespace-nowrap flex justify-center items-center"> <div className="contact w-36 h-16 flex items-center justify-center"> @@ -28,9 +28,9 @@ export default function Layout ({userData}) </a> </div> }/> <div className="socials flex flex-row place-content-center gap-1"> - <Button link={<a id="contact" href="https://github.com/realtradam" className=" w-10 h-10 text-center whitespace-nowrap flex justify-center items-center"><i className="fa-brands fa-github"></i></a>} width={10} height={16} spinner={3}/> - <Button link={<a id="contact" href="https://www.linkedin.com/in/adammalczewski/" className=" w-10 h-10 text-center whitespace-nowrap flex justify-center items-center"><i className="fa-brands fa-linkedin"></i></a>} width={10} height={16} spinner={3}/> - <Button link={<a id="contact" href="https://tradam.itch.io" className=" w-10 h-10 text-center whitespace-nowrap flex justify-center items-center"><i className="fa-brands fa-itch-io"></i></a>} width={10} height={16} spinner={3}/> + <Button link={<a id="contact" href="https://github.com/realtradam" className="absolute flex top-0 left-0 w-10 h-16 text-stone-50 bg-transparent justify-center items-center"><i className="fa-brands fa-github"></i></a>} width={10} height={16} spinner={3}/> + <Button link={<a id="contact" href="https://www.linkedin.com/in/adammalczewski/" className="absolute flex top-0 left-0 w-10 h-16 text-stone-50 bg-transparent justify-center items-center"><i className="fa-brands fa-linkedin"></i></a>} width={10} height={16} spinner={3}/> + <Button link={<a id="contact" href="https://tradam.itch.io" className="absolute flex top-0 left-0 w-10 h-16 text-stone-50 bg-transparent justify-center items-center"><i className="fa-brands fa-itch-io"></i></a>} width={10} height={16} spinner={3}/> </div> </div> </div> diff --git a/app/javascript/routes/index.jsx b/app/javascript/routes/index.jsx index 235f41b..6ab155f 100644 --- a/app/javascript/routes/index.jsx +++ b/app/javascript/routes/index.jsx @@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react"; import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; import Home from "../components/Home"; import Blogs from "../components/Blogs"; +import Games from "../components/Games"; import Layout from "../components/Layout"; export default function index() @@ -24,6 +25,7 @@ export default function index() <Route path="/" element = {<Layout userData={userData}/>}> <Route index element={<Home />} /> <Route path="/blogs" element={<Blogs />} /> + <Route path="/games" element={<Games />} /> </Route> </Routes> </Router> diff --git a/config/routes.rb b/config/routes.rb index 7d8a766..cc5e70e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,6 @@ Rails.application.routes.draw do namespace :api do namespace :v1 do - resources :games # USERS get 'users/index', to: 'users#index' @@ -10,7 +9,8 @@ Rails.application.routes.draw do #get 'users/delete' # GAMES - + get 'games/*path/:file', to: 'games#index' + #resources :games # BLOGS get 'blogs/index', to: 'blog#index' |
