aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/pages/games.js
blob: 75b5e444751e960d72f31a1f7f0cb462a63ae5d1 (plain) (blame)
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
53
54
55
56
57
58
59
60
61
62
import React, { useEffect, useState } from 'react';
import { useLocation, Link } from "react-router-dom";

import "./games.css"
import GameEntry from './game';

export default function Games(prop) {
    const { token } = prop;
    const [games, setGames] = useState([]);
    const location = useLocation();

    useEffect(() => {
        document.querySelectorAll(".games-page-item-body").forEach((game, index) => {
            game.innerHTML = "";
        })

        const fetchGames = async () => {
            try {
                const response = await fetch("https://lp.ardapektezol.com/api/v1/games", {
                    headers: {
                        'Authorization': token
                    }
                });

                const data = await response.json();
                setGames(data.data);
                pageLoad();
            } catch (err) {
                console.error("Error fetching games:", err);
            }
        };

        fetchGames();

        function pageLoad() {
            const loaders = document.querySelectorAll(".loader");
            loaders.forEach((loader) => {
                loader.style.display = "none";
            });
        }
    }, [token]);

    return (
        <div className='games-page'>
            <section className='games-page-header'>
                <span><b>Games list</b></span>
            </section>

            <section>
                <div className='games-page-content'>
                    <div className='games-page-item-content'>
                        <div className='loader loader-game'></div>
                        <div className='loader loader-game'></div>
                        {games.map((game, index) => (
                            <GameEntry gameInfo={game} key={index} />
                        ))}
                    </div>
                </div>
            </section>
        </div>
    );
}