diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2025-01-30 14:43:17 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-30 14:43:17 +0300 |
| commit | 681f7d3ba097cd8d204ff3ac4dae01432d323e5b (patch) | |
| tree | 8578439ebb74d6cefc2e07177689a40ed6b15464 /frontend/src/pages/Maplist.tsx | |
| parent | wr: finale 2 - 0 portals (#258) (diff) | |
| download | lphub-681f7d3ba097cd8d204ff3ac4dae01432d323e5b.tar.gz lphub-681f7d3ba097cd8d204ff3ac4dae01432d323e5b.tar.bz2 lphub-681f7d3ba097cd8d204ff3ac4dae01432d323e5b.zip | |
feat/frontend: dynamic title and meta descriptions (#261)
Diffstat (limited to 'frontend/src/pages/Maplist.tsx')
| -rw-r--r-- | frontend/src/pages/Maplist.tsx | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/frontend/src/pages/Maplist.tsx b/frontend/src/pages/Maplist.tsx index 8fc52b0..04938cf 100644 --- a/frontend/src/pages/Maplist.tsx +++ b/frontend/src/pages/Maplist.tsx | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | import React, { useEffect } from "react"; | 1 | import React, { useEffect } from "react"; |
| 2 | import { Link, useLocation, useNavigate, useParams } from "react-router-dom"; | 2 | import { Link, useLocation, useNavigate, useParams } from "react-router-dom"; |
| 3 | import { Helmet } from "react-helmet"; | ||
| 3 | 4 | ||
| 4 | import "@css/Maplist.css"; | 5 | import "@css/Maplist.css"; |
| 5 | import { API } from "@api/Api"; | 6 | import { API } from "@api/Api"; |
| @@ -25,9 +26,9 @@ const Maplist: React.FC = () => { | |||
| 25 | const navigate = useNavigate(); | 26 | const navigate = useNavigate(); |
| 26 | 27 | ||
| 27 | function _update_currently_selected(catNum2: number) { | 28 | function _update_currently_selected(catNum2: number) { |
| 28 | setCurrentlySelected(catNum2); | 29 | setCurrentlySelected(catNum2); |
| 29 | navigate("/games/" + game?.id + "?cat=" + catNum2); | 30 | navigate("/games/" + game?.id + "?cat=" + catNum2); |
| 30 | setHasClicked(true); | 31 | setHasClicked(true); |
| 31 | } | 32 | } |
| 32 | 33 | ||
| 33 | const _fetch_chapters = async (chapter_id: string) => { | 34 | const _fetch_chapters = async (chapter_id: string) => { |
| @@ -52,12 +53,12 @@ const Maplist: React.FC = () => { | |||
| 52 | // location query params | 53 | // location query params |
| 53 | const queryParams = new URLSearchParams(location.search); | 54 | const queryParams = new URLSearchParams(location.search); |
| 54 | if (queryParams.get("chapter")) { | 55 | if (queryParams.get("chapter")) { |
| 55 | let cat = parseFloat(queryParams.get("chapter") || ""); | 56 | let cat = parseFloat(queryParams.get("chapter") || ""); |
| 56 | if (gameId == 2) { | 57 | if (gameId == 2) { |
| 57 | cat += 10; | 58 | cat += 10; |
| 58 | } | 59 | } |
| 59 | _fetch_chapters(cat.toString()); | 60 | _fetch_chapters(cat.toString()); |
| 60 | } | 61 | } |
| 61 | 62 | ||
| 62 | const _fetch_game = async () => { | 63 | const _fetch_game = async () => { |
| 63 | const games = await API.get_games(); | 64 | const games = await API.get_games(); |
| @@ -68,7 +69,7 @@ const Maplist: React.FC = () => { | |||
| 68 | setLoad(false); | 69 | setLoad(false); |
| 69 | } | 70 | } |
| 70 | }; | 71 | }; |
| 71 | 72 | ||
| 72 | const _fetch_game_chapters = async () => { | 73 | const _fetch_game_chapters = async () => { |
| 73 | const games_chapters = await API.get_games_chapters(gameId.toString()); | 74 | const games_chapters = await API.get_games_chapters(gameId.toString()); |
| 74 | setGameChapters(games_chapters); | 75 | setGameChapters(games_chapters); |
| @@ -81,7 +82,7 @@ const Maplist: React.FC = () => { | |||
| 81 | }, []); | 82 | }, []); |
| 82 | 83 | ||
| 83 | useEffect(() => { | 84 | useEffect(() => { |
| 84 | const queryParams = new URLSearchParams(location.search); | 85 | const queryParams = new URLSearchParams(location.search); |
| 85 | if (gameChapters != undefined && !queryParams.get("chapter")) { | 86 | if (gameChapters != undefined && !queryParams.get("chapter")) { |
| 86 | _fetch_chapters(gameChapters!.chapters[0].id.toString()); | 87 | _fetch_chapters(gameChapters!.chapters[0].id.toString()); |
| 87 | } | 88 | } |
| @@ -91,6 +92,9 @@ const Maplist: React.FC = () => { | |||
| 91 | 92 | ||
| 92 | return ( | 93 | return ( |
| 93 | <main> | 94 | <main> |
| 95 | <Helmet> | ||
| 96 | <title>LPHUB | Maplist</title> | ||
| 97 | </Helmet> | ||
| 94 | <section style={{ marginTop: "20px" }}> | 98 | <section style={{ marginTop: "20px" }}> |
| 95 | <Link to="/games"> | 99 | <Link to="/games"> |
| 96 | <button className="nav-button" style={{ borderRadius: "20px" }}> | 100 | <button className="nav-button" style={{ borderRadius: "20px" }}> |
| @@ -121,7 +125,7 @@ const Maplist: React.FC = () => { | |||
| 121 | </div> | 125 | </div> |
| 122 | <div className="game-header-categories"> | 126 | <div className="game-header-categories"> |
| 123 | {game?.category_portals.map((cat, index) => ( | 127 | {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)}}> | 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) }}> |
| 125 | <span>{cat.category.name}</span> | 129 | <span>{cat.category.name}</span> |
| 126 | </button> | 130 | </button> |
| 127 | ))} | 131 | ))} |
| @@ -132,26 +136,26 @@ const Maplist: React.FC = () => { | |||
| 132 | <div> | 136 | <div> |
| 133 | <section className="chapter-select-container"> | 137 | <section className="chapter-select-container"> |
| 134 | <div> | 138 | <div> |
| 135 | <span style={{fontSize: "18px", transform: "translateY(5px)", display: "block", marginTop: "10px"}}>{curChapter?.chapter.name.split(" - ")[0]}</span> | 139 | <span style={{ fontSize: "18px", transform: "translateY(5px)", display: "block", marginTop: "10px" }}>{curChapter?.chapter.name.split(" - ")[0]}</span> |
| 136 | </div> | 140 | </div> |
| 137 | <div onClick={_handle_dropdown_click} className="dropdown"> | 141 | <div onClick={_handle_dropdown_click} className="dropdown"> |
| 138 | <span>{curChapter?.chapter.name.split(" - ")[1]}</span> | 142 | <span>{curChapter?.chapter.name.split(" - ")[1]}</span> |
| 139 | <i className="triangle"></i> | 143 | <i className="triangle"></i> |
| 140 | </div> | 144 | </div> |
| 141 | <div className="dropdown-elements" style={{display: dropdownActive}}> | 145 | <div className="dropdown-elements" style={{ display: dropdownActive }}> |
| 142 | {gameChapters?.chapters.map((chapter, i) => { | 146 | {gameChapters?.chapters.map((chapter, i) => { |
| 143 | return <div className="dropdown-element" onClick={() => {_fetch_chapters(chapter.id.toString()); _handle_dropdown_click()}}>{chapter.name}</div> | 147 | return <div className="dropdown-element" onClick={() => { _fetch_chapters(chapter.id.toString()); _handle_dropdown_click() }}>{chapter.name}</div> |
| 144 | }) | 148 | }) |
| 145 | 149 | ||
| 146 | } | 150 | } |
| 147 | </div> | 151 | </div> |
| 148 | </section> | 152 | </section> |
| 149 | <section className="maplist"> | 153 | <section className="maplist"> |
| 150 | {curChapter?.maps.map((map, i) => { | 154 | {curChapter?.maps.map((map, i) => { |
| 151 | return <div className="maplist-entry"> | 155 | return <div className="maplist-entry"> |
| 152 | <Link to={`/maps/${map.id}`}> | 156 | <Link to={`/maps/${map.id}`}> |
| 153 | <span>{map.name}</span> | 157 | <span>{map.name}</span> |
| 154 | <div className="map-entry-image" style={{backgroundImage: `url(${map.image})`}}> | 158 | <div className="map-entry-image" style={{ backgroundImage: `url(${map.image})` }}> |
| 155 | <div className="blur map"> | 159 | <div className="blur map"> |
| 156 | <span>{map.is_disabled ? map.category_portals[0].portal_count : map.category_portals.find( | 160 | <span>{map.is_disabled ? map.category_portals[0].portal_count : map.category_portals.find( |
| 157 | (obj) => obj.category.id === catNum + 1 | 161 | (obj) => obj.category.id === catNum + 1 |
| @@ -169,9 +173,9 @@ const Maplist: React.FC = () => { | |||
| 169 | <div className="difficulty-point"></div> | 173 | <div className="difficulty-point"></div> |
| 170 | </div> | 174 | </div> |
| 171 | </div> | 175 | </div> |
| 172 | </Link> | 176 | </Link> |
| 173 | </div> | 177 | </div> |
| 174 | })} | 178 | })} |
| 175 | </section> | 179 | </section> |
| 176 | </div> | 180 | </div> |
| 177 | </section> | 181 | </section> |