aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/pages/Maplist.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/pages/Maplist.tsx')
-rw-r--r--frontend/src/pages/Maplist.tsx165
1 files changed, 109 insertions, 56 deletions
diff --git a/frontend/src/pages/Maplist.tsx b/frontend/src/pages/Maplist.tsx
index 04938cf..5138964 100644
--- a/frontend/src/pages/Maplist.tsx
+++ b/frontend/src/pages/Maplist.tsx
@@ -1,11 +1,11 @@
1import React, { useEffect } from "react"; 1import React, { useEffect } from 'react';
2import { Link, useLocation, useNavigate, useParams } from "react-router-dom"; 2import { Link, useLocation, useNavigate, useParams } from 'react-router-dom';
3import { Helmet } from "react-helmet"; 3import { Helmet } from 'react-helmet';
4 4
5import "@css/Maplist.css"; 5import '@css/Maplist.css';
6import { API } from "@api/Api"; 6import { API } from '@api/Api';
7import { Game } from "@customTypes/Game"; 7import { Game } from '@customTypes/Game';
8import { GameChapter, GamesChapters } from "@customTypes/Chapters"; 8import { GameChapter, GamesChapters } from '@customTypes/Chapters';
9 9
10const Maplist: React.FC = () => { 10const Maplist: React.FC = () => {
11 const [game, setGame] = React.useState<Game | null>(null); 11 const [game, setGame] = React.useState<Game | null>(null);
@@ -19,41 +19,41 @@ const Maplist: React.FC = () => {
19 const [curChapter, setCurChapter] = React.useState<GameChapter>(); 19 const [curChapter, setCurChapter] = React.useState<GameChapter>();
20 const [numChapters, setNumChapters] = React.useState<number>(0); 20 const [numChapters, setNumChapters] = React.useState<number>(0);
21 21
22 const [dropdownActive, setDropdownActive] = React.useState("none"); 22 const [dropdownActive, setDropdownActive] = React.useState('none');
23 23
24 const params = useParams<{ id: string, chapter: string }>(); 24 const params = useParams<{ id: string; chapter: string }>();
25 const location = useLocation(); 25 const location = useLocation();
26 const navigate = useNavigate(); 26 const navigate = useNavigate();
27 27
28 function _update_currently_selected(catNum2: number) { 28 function _update_currently_selected(catNum2: number) {
29 setCurrentlySelected(catNum2); 29 setCurrentlySelected(catNum2);
30 navigate("/games/" + game?.id + "?cat=" + catNum2); 30 navigate('/games/' + game?.id + '?cat=' + catNum2);
31 setHasClicked(true); 31 setHasClicked(true);
32 } 32 }
33 33
34 const _fetch_chapters = async (chapter_id: string) => { 34 const _fetch_chapters = async (chapter_id: string) => {
35 const chapters = await API.get_chapters(chapter_id); 35 const chapters = await API.get_chapters(chapter_id);
36 setCurChapter(chapters); 36 setCurChapter(chapters);
37 } 37 };
38 38
39 const _handle_dropdown_click = () => { 39 const _handle_dropdown_click = () => {
40 if (dropdownActive == "none") { 40 if (dropdownActive == 'none') {
41 setDropdownActive("block"); 41 setDropdownActive('block');
42 } else { 42 } else {
43 setDropdownActive("none"); 43 setDropdownActive('none');
44 } 44 }
45 } 45 };
46 46
47 // im sorry but im too lazy to fix this right now 47 // im sorry but im too lazy to fix this right now
48 useEffect(() => { 48 useEffect(() => {
49 // gameID 49 // gameID
50 const gameId = parseFloat(params.id || ""); 50 const gameId = parseFloat(params.id || '');
51 setId(gameId); 51 setId(gameId);
52 52
53 // location query params 53 // location query params
54 const queryParams = new URLSearchParams(location.search); 54 const queryParams = new URLSearchParams(location.search);
55 if (queryParams.get("chapter")) { 55 if (queryParams.get('chapter')) {
56 let cat = parseFloat(queryParams.get("chapter") || ""); 56 let cat = parseFloat(queryParams.get('chapter') || '');
57 if (gameId == 2) { 57 if (gameId == 2) {
58 cat += 10; 58 cat += 10;
59 } 59 }
@@ -62,7 +62,7 @@ const Maplist: React.FC = () => {
62 62
63 const _fetch_game = async () => { 63 const _fetch_game = async () => {
64 const games = await API.get_games(); 64 const games = await API.get_games();
65 const foundGame = games.find((game) => game.id === gameId); 65 const foundGame = games.find(game => game.id === gameId);
66 // console.log(foundGame) 66 // console.log(foundGame)
67 if (foundGame) { 67 if (foundGame) {
68 setGame(foundGame); 68 setGame(foundGame);
@@ -74,7 +74,7 @@ const Maplist: React.FC = () => {
74 const games_chapters = await API.get_games_chapters(gameId.toString()); 74 const games_chapters = await API.get_games_chapters(gameId.toString());
75 setGameChapters(games_chapters); 75 setGameChapters(games_chapters);
76 setNumChapters(games_chapters.chapters.length); 76 setNumChapters(games_chapters.chapters.length);
77 } 77 };
78 78
79 setLoad(true); 79 setLoad(true);
80 _fetch_game(); 80 _fetch_game();
@@ -83,21 +83,19 @@ const Maplist: React.FC = () => {
83 83
84 useEffect(() => { 84 useEffect(() => {
85 const queryParams = new URLSearchParams(location.search); 85 const queryParams = new URLSearchParams(location.search);
86 if (gameChapters != undefined && !queryParams.get("chapter")) { 86 if (gameChapters != undefined && !queryParams.get('chapter')) {
87 _fetch_chapters(gameChapters!.chapters[0].id.toString()); 87 _fetch_chapters(gameChapters!.chapters[0].id.toString());
88 } 88 }
89 }, [gameChapters]) 89 }, [gameChapters]);
90
91
92 90
93 return ( 91 return (
94 <main> 92 <main>
95 <Helmet> 93 <Helmet>
96 <title>LPHUB | Maplist</title> 94 <title>LPHUB | Maplist</title>
97 </Helmet> 95 </Helmet>
98 <section style={{ marginTop: "20px" }}> 96 <section style={{ marginTop: '20px' }}>
99 <Link to="/games"> 97 <Link to="/games">
100 <button className="nav-button" style={{ borderRadius: "20px" }}> 98 <button className="nav-button" style={{ borderRadius: '20px' }}>
101 <i className="triangle"></i> 99 <i className="triangle"></i>
102 <span>Games List</span> 100 <span>Games List</span>
103 </button> 101 </button>
@@ -117,7 +115,7 @@ const Maplist: React.FC = () => {
117 <h2 className="portal-count"> 115 <h2 className="portal-count">
118 { 116 {
119 game?.category_portals.find( 117 game?.category_portals.find(
120 (obj) => obj.category.id === catNum + 1 118 obj => obj.category.id === catNum + 1
121 )?.portal_count 119 )?.portal_count
122 } 120 }
123 </h2> 121 </h2>
@@ -125,7 +123,19 @@ const Maplist: React.FC = () => {
125 </div> 123 </div>
126 <div className="game-header-categories"> 124 <div className="game-header-categories">
127 {game?.category_portals.map((cat, index) => ( 125 {game?.category_portals.map((cat, index) => (
128 <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) }}> 126 <button
127 key={index}
128 className={
129 currentlySelected == cat.category.id ||
130 (cat.category.id - 1 == catNum && !hasClicked)
131 ? 'game-cat-button selected'
132 : 'game-cat-button'
133 }
134 onClick={() => {
135 setCatNum(cat.category.id - 1);
136 _update_currently_selected(cat.category.id);
137 }}
138 >
129 <span>{cat.category.name}</span> 139 <span>{cat.category.name}</span>
130 </button> 140 </button>
131 ))} 141 ))}
@@ -136,45 +146,88 @@ const Maplist: React.FC = () => {
136 <div> 146 <div>
137 <section className="chapter-select-container"> 147 <section className="chapter-select-container">
138 <div> 148 <div>
139 <span style={{ fontSize: "18px", transform: "translateY(5px)", display: "block", marginTop: "10px" }}>{curChapter?.chapter.name.split(" - ")[0]}</span> 149 <span
150 style={{
151 fontSize: '18px',
152 transform: 'translateY(5px)',
153 display: 'block',
154 marginTop: '10px',
155 }}
156 >
157 {curChapter?.chapter.name.split(' - ')[0]}
158 </span>
140 </div> 159 </div>
141 <div onClick={_handle_dropdown_click} className="dropdown"> 160 <div onClick={_handle_dropdown_click} className="dropdown">
142 <span>{curChapter?.chapter.name.split(" - ")[1]}</span> 161 <span>{curChapter?.chapter.name.split(' - ')[1]}</span>
143 <i className="triangle"></i> 162 <i className="triangle"></i>
144 </div> 163 </div>
145 <div className="dropdown-elements" style={{ display: dropdownActive }}> 164 <div
165 className="dropdown-elements"
166 style={{ display: dropdownActive }}
167 >
146 {gameChapters?.chapters.map((chapter, i) => { 168 {gameChapters?.chapters.map((chapter, i) => {
147 return <div className="dropdown-element" onClick={() => { _fetch_chapters(chapter.id.toString()); _handle_dropdown_click() }}>{chapter.name}</div> 169 return (
148 }) 170 <div
149 171 className="dropdown-element"
150 } 172 onClick={() => {
173 _fetch_chapters(chapter.id.toString());
174 _handle_dropdown_click();
175 }}
176 >
177 {chapter.name}
178 </div>
179 );
180 })}
151 </div> 181 </div>
152 </section> 182 </section>
153 <section className="maplist"> 183 <section className="maplist">
154 {curChapter?.maps.map((map, i) => { 184 {curChapter?.maps.map((map, i) => {
155 return <div className="maplist-entry"> 185 return (
156 <Link to={`/maps/${map.id}`}> 186 <div className="maplist-entry">
157 <span>{map.name}</span> 187 <Link to={`/maps/${map.id}`}>
158 <div className="map-entry-image" style={{ backgroundImage: `url(${map.image})` }}> 188 <span>{map.name}</span>
159 <div className="blur map"> 189 <div
160 <span>{map.is_disabled ? map.category_portals[0].portal_count : map.category_portals.find( 190 className="map-entry-image"
161 (obj) => obj.category.id === catNum + 1 191 style={{ backgroundImage: `url(${map.image})` }}
162 )?.portal_count}</span> 192 >
163 <span>portals</span> 193 <div className="blur map">
194 <span>
195 {map.is_disabled
196 ? map.category_portals[0].portal_count
197 : map.category_portals.find(
198 obj => obj.category.id === catNum + 1
199 )?.portal_count}
200 </span>
201 <span>portals</span>
202 </div>
164 </div> 203 </div>
165 </div> 204 <div className="difficulty-bar">
166 <div className="difficulty-bar"> 205 {/* <span>Difficulty:</span> */}
167 {/* <span>Difficulty:</span> */} 206 <div
168 <div className={map.difficulty == 0 ? "one" : map.difficulty == 1 ? "two" : map.difficulty == 2 ? "three" : map.difficulty == 3 ? "four" : map.difficulty == 4 ? "five" : "one"}> 207 className={
169 <div className="difficulty-point"></div> 208 map.difficulty == 0
170 <div className="difficulty-point"></div> 209 ? 'one'
171 <div className="difficulty-point"></div> 210 : map.difficulty == 1
172 <div className="difficulty-point"></div> 211 ? 'two'
173 <div className="difficulty-point"></div> 212 : map.difficulty == 2
213 ? 'three'
214 : map.difficulty == 3
215 ? 'four'
216 : map.difficulty == 4
217 ? 'five'
218 : 'one'
219 }
220 >
221 <div className="difficulty-point"></div>
222 <div className="difficulty-point"></div>
223 <div className="difficulty-point"></div>
224 <div className="difficulty-point"></div>
225 <div className="difficulty-point"></div>
226 </div>
174 </div> 227 </div>
175 </div> 228 </Link>
176 </Link> 229 </div>
177 </div> 230 );
178 })} 231 })}
179 </section> 232 </section>
180 </div> 233 </div>