aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/pages
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/pages')
-rw-r--r--frontend/src/pages/Games.tsx6
-rw-r--r--frontend/src/pages/Maplist.tsx183
2 files changed, 184 insertions, 5 deletions
diff --git a/frontend/src/pages/Games.tsx b/frontend/src/pages/Games.tsx
index ce3db76..eb7177f 100644
--- a/frontend/src/pages/Games.tsx
+++ b/frontend/src/pages/Games.tsx
@@ -18,13 +18,9 @@ const Games: React.FC = () => {
18 loaders.forEach((loader) => { 18 loaders.forEach((loader) => {
19 (loader as HTMLElement).style.display = "none"; 19 (loader as HTMLElement).style.display = "none";
20 }); 20 });
21 } 21 }
22 22
23 React.useEffect(() => { 23 React.useEffect(() => {
24 document.querySelectorAll(".games-page-item-body").forEach((game, index) => {
25 game.innerHTML = "";
26 });
27
28 _fetch_games(); 24 _fetch_games();
29 _page_load(); 25 _page_load();
30 }, []); 26 }, []);
diff --git a/frontend/src/pages/Maplist.tsx b/frontend/src/pages/Maplist.tsx
new file mode 100644
index 0000000..b1b1664
--- /dev/null
+++ b/frontend/src/pages/Maplist.tsx
@@ -0,0 +1,183 @@
1import React, { useEffect } from "react";
2import { Link, useLocation, useParams } from "react-router-dom";
3
4import "../css/Maplist.css";
5import { API } from "../api/Api";
6import { Game, GameChapters } from "../types/Game";
7import { GameChapter, GamesChapters } from "../types/Chapters";
8import { Map } from "../types/Map";
9
10const Maplist: React.FC = () => {
11 const [game, setGame] = React.useState<Game | null>(null);
12 const [catNum, setCatNum] = React.useState(0);
13 const [id, setId] = React.useState(0);
14 const [category, setCategory] = React.useState(0);
15 const [load, setLoad] = React.useState(false);
16 const [currentlySelected, setCurrentlySelected] = React.useState<number>(0);
17 const [hasClicked, setHasClicked] = React.useState(false);
18 const [gameChapters, setGameChapters] = React.useState<GamesChapters>();
19 const [curChapter, setCurChapter] = React.useState<GameChapter>();
20 const [numChapters, setNumChapters] = React.useState<number>(0);
21
22 const [dropdownActive, setDropdownActive] = React.useState("none");
23
24 const params = useParams<{ id: string }>();
25 const location = useLocation();
26
27 function _update_currently_selected(catNum2: number) {
28 setCurrentlySelected(catNum2);
29 setHasClicked(true);
30 }
31
32 const _fetch_chapters = async (chapter_id: string) => {
33 const chapters = await API.get_chapters(chapter_id);
34 setCurChapter(chapters);
35 }
36
37 const _handle_dropdown_click = () => {
38 if (dropdownActive == "none") {
39 setDropdownActive("block");
40 } else {
41 setDropdownActive("none");
42 }
43 }
44
45 // im sorry but im too lazy to fix this right now
46 useEffect(() => {
47 // gameID
48 const gameId = parseFloat(params.id || "");
49 setId(gameId);
50
51 // location query params
52 const queryParams = new URLSearchParams(location.search);
53 if (queryParams.get("cat")) {
54 const cat = parseFloat(queryParams.get("cat") || "");
55 setCategory(cat);
56 setCatNum(cat - 1);
57 }
58
59 const _fetch_game = async () => {
60 const games = await API.get_games();
61 const foundGame = games.find((game) => game.id === gameId);
62 // console.log(foundGame)
63 if (foundGame) {
64 setGame(foundGame);
65 }
66 };
67
68 const _fetch_game_chapters = async () => {
69 const games_chapters = await API.get_games_chapters(gameId.toString());
70 setGameChapters(games_chapters);
71 setNumChapters(games_chapters.chapters.length);
72 }
73
74 const _fetch_maps = async () => {
75 const maps = await API.get_games_maps(gameId.toString());
76 setLoad(true);
77 }
78
79 _fetch_game();
80 _fetch_game_chapters();
81 _fetch_maps();
82 }, []);
83
84 useEffect(() => {
85 if (gameChapters != undefined) {
86 _fetch_chapters(gameChapters!.chapters[0].id.toString());
87 }
88 }, [gameChapters])
89
90
91
92 return (
93 <main>
94 <section style={{ marginTop: "20px" }}>
95 <Link to="/games">
96 <button className="nav-button" style={{ borderRadius: "20px" }}>
97 <i className="triangle"></i>
98 <span>Games list</span>
99 </button>
100 </Link>
101 </section>
102 {!load ? (
103 <div></div>
104 ) : (
105 <section>
106 <h1>{game?.name}</h1>
107 <div
108 style={{ backgroundImage: `url(${game?.image})` }}
109 className="game-header"
110 >
111 <div className="blur">
112 <div className="game-header-portal-count">
113 <h2>
114 {
115 game?.category_portals.find(
116 (obj) => obj.category.id === catNum + 1
117 )?.portal_count
118 }
119 </h2>
120 <h3>portals</h3>
121 </div>
122 <div className="game-header-categories">
123 {game?.category_portals.map((cat, index) => (
124 <button key={index} className={currentlySelected == cat.category.id || cat.category.id - 1 == catNum && !hasClicked ? "game-cat-button selected" : "game-cat-button"} onClick={() => {setCatNum(cat.category.id - 1); _update_currently_selected(cat.category.id)}}>
125 <span>{cat.category.name}</span>
126 </button>
127 ))}
128 </div>
129 </div>
130 </div>
131
132 <div>
133 <section className="chapter-select-container">
134 <div>
135 <span style={{fontSize: "18px", transform: "translateY(5px)", display: "block", marginTop: "10px"}}>{curChapter?.chapter.name.split(" - ")[0]}</span>
136 </div>
137 <div onClick={_handle_dropdown_click} className="dropdown">
138 <span>{curChapter?.chapter.name.split(" - ")[1]}</span>
139 <i className="triangle"></i>
140 </div>
141 <div className="dropdown-elements" style={{display: dropdownActive}}>
142 {gameChapters?.chapters.map((chapter, i) => {
143 return <div className="dropdown-element" onClick={() => {_fetch_chapters(chapter.id.toString()); _handle_dropdown_click()}}>{chapter.name}</div>
144 })
145
146 }
147 </div>
148 </section>
149 <section className="maplist">
150 {curChapter?.maps.map((map, i) => {
151 return <div className="maplist-entry">
152 <Link to={`/maps/${map.id}`}>
153 <span>{map.name}</span>
154 <div className="map-entry-image" style={{backgroundImage: `url(${map.image})`}}>
155 <div className="blur map">
156 <span>{map.is_disabled ? map.category_portals[0].portal_count : map.category_portals.find(
157 (obj) => obj.category.id === catNum + 1
158 )?.portal_count}</span>
159 <span>portals</span>
160 </div>
161 </div>
162 <div className="difficulty-bar">
163 <span>Difficulty:</span>
164 <div className={map.difficulty == 0 ? "one" : map.difficulty == 1 ? "two" : map.difficulty == 2 ? "three" : map.difficulty == 3 ? "four" : map.difficulty == 4 ? "five" : "one"}>
165 <div className="difficulty-point"></div>
166 <div className="difficulty-point"></div>
167 <div className="difficulty-point"></div>
168 <div className="difficulty-point"></div>
169 <div className="difficulty-point"></div>
170 </div>
171 </div>
172 </Link>
173 </div>
174 })}
175 </section>
176 </div>
177 </section>
178 )}
179 </main>
180 );
181};
182
183export default Maplist;