diff options
Diffstat (limited to 'frontend/src/components/pages/games.js')
| -rw-r--r-- | frontend/src/components/pages/games.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/frontend/src/components/pages/games.js b/frontend/src/components/pages/games.js new file mode 100644 index 0000000..8c27151 --- /dev/null +++ b/frontend/src/components/pages/games.js | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | import React, { useEffect, useState } from 'react'; | ||
| 2 | import { useLocation, Link } from "react-router-dom"; | ||
| 3 | |||
| 4 | import "./games.css" | ||
| 5 | import GameEntry from './game'; | ||
| 6 | |||
| 7 | export default function Games(prop) { | ||
| 8 | const { token } = prop; | ||
| 9 | const [games, setGames] = useState([]); | ||
| 10 | const location = useLocation(); | ||
| 11 | |||
| 12 | useEffect(() => { | ||
| 13 | const fetchGames = async () => { | ||
| 14 | try { | ||
| 15 | const response = await fetch("https://lp.ardapektezol.com/api/v1/games", { | ||
| 16 | headers: { | ||
| 17 | 'Authorization': token | ||
| 18 | } | ||
| 19 | }); | ||
| 20 | |||
| 21 | const data = await response.json(); | ||
| 22 | setGames(data.data); | ||
| 23 | pageLoad(); | ||
| 24 | } catch (err) { | ||
| 25 | console.error("Error fetching games:", err); | ||
| 26 | } | ||
| 27 | }; | ||
| 28 | |||
| 29 | fetchGames(); | ||
| 30 | |||
| 31 | function pageLoad() { | ||
| 32 | const loaders = document.querySelectorAll(".loader"); | ||
| 33 | loaders.forEach((loader) => { | ||
| 34 | loader.style.display = "none"; | ||
| 35 | }); | ||
| 36 | } | ||
| 37 | }, [token]); | ||
| 38 | |||
| 39 | return ( | ||
| 40 | <div className='games-page'> | ||
| 41 | <section className='games-page-header'> | ||
| 42 | <span><b>Games list</b></span> | ||
| 43 | </section> | ||
| 44 | |||
| 45 | <section> | ||
| 46 | <div className='games-page-content'> | ||
| 47 | <div className='games-page-item-content'> | ||
| 48 | <div className='loader loader-game'></div> | ||
| 49 | <div className='loader loader-game'></div> | ||
| 50 | {games.map((game, index) => ( | ||
| 51 | <GameEntry gameInfo={game} key={index} /> | ||
| 52 | ))} | ||
| 53 | </div> | ||
| 54 | </div> | ||
| 55 | </section> | ||
| 56 | </div> | ||
| 57 | ); | ||
| 58 | } | ||