import React, { useEffect } from "react"; import { Link, useLocation, useNavigate, useParams } from "react-router-dom"; import { Helmet } from "react-helmet"; import { API } from "@api/Api.ts"; import { Game } from "@customTypes/Game.ts"; import { GameChapter, GamesChapters } from "@customTypes/Chapters.ts"; import Map from "./Components/Map"; import BreadcrumbNav from "@components/BreadcrumbNav/BreadcrumbNav"; const Maplist: React.FC = () => { const [game, setGame] = React.useState(null); const [catNum, setCatNum] = React.useState(0); const [id, setId] = React.useState(0); const [load, setLoad] = React.useState(false); const [currentlySelected, setCurrentlySelected] = React.useState(0); const [hasClicked, setHasClicked] = React.useState(false); const [gameChapters, setGameChapters] = React.useState(); const [curChapter, setCurChapter] = React.useState(); const [numChapters, setNumChapters] = React.useState(0); const [dropdownActive, setDropdownActive] = React.useState("none"); const params = useParams<{ id: string; chapter: string }>(); const location = useLocation(); const navigate = useNavigate(); function _update_currently_selected(catNum2: number) { setCurrentlySelected(catNum2); // navigate("/games/" + game?.id + "?cat=" + catNum2); setHasClicked(true); } const _fetch_chapters = async (chapter_id: string) => { const chapters = await API.get_chapters(chapter_id); setCurChapter(chapters); }; const _handle_dropdown_click = () => { if (dropdownActive === "none") { setDropdownActive("block"); } else { setDropdownActive("none"); } }; // im sorry but im too lazy to fix this right now useEffect(() => { // gameID const gameId = parseFloat(params.id || ""); setId(gameId); // location query params const queryParams = new URLSearchParams(location.search); if (queryParams.get("chapter")) { let chapter = parseFloat(queryParams.get("chapter") || ""); if (gameId === 2) { chapter += 10; } _fetch_chapters(chapter.toString()); } if (queryParams.get("cat")) { let cat = parseFloat(queryParams.get("cat") || ""); setCatNum(cat - 1); } const _fetch_game = async () => { const games = await API.get_games(); const foundGame = games.find(game => game.id === gameId); // console.log(foundGame) if (foundGame) { setGame(foundGame); setLoad(false); } }; const _fetch_game_chapters = async () => { const games_chapters = await API.get_games_chapters(gameId.toString()); setGameChapters(games_chapters); setNumChapters(games_chapters.chapters.length); }; setLoad(true); _fetch_game(); _fetch_game_chapters(); }, [location]); useEffect(() => { const queryParams = new URLSearchParams(location.search); if (gameChapters !== undefined && !queryParams.get("chapter")) { _fetch_chapters(gameChapters!.chapters[0].id.toString()); } }, [gameChapters, location.search]); return (
LPHUB | Maplist {load ? (
) : (

{game?.name}

{ game?.category_portals.find( obj => obj.category.id === catNum + 1 )?.portal_count } portals
{game?.category_portals.map((cat, index) => ( ))}
{curChapter?.chapter.name.split(" - ")[0]}
{curChapter?.chapter.name.split(" - ")[1]}
{gameChapters?.chapters.map((chapter, i) => { return (
{ _fetch_chapters(chapter.id.toString()); _handle_dropdown_click(); }} > {chapter.name}
); })}
{curChapter?.maps.map((map, i) => { return ( ); })}
)}
); }; export default Maplist;