diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-09-03 00:08:53 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-09-03 00:08:53 +0300 |
| commit | a65d6d9127c3fa7f6a8ecaec5d1ffd1f47c2bc98 (patch) | |
| tree | edf8630e9d6426124dd49854af0cb703ebc5b710 /frontend/src/pages/Maps.tsx | |
| parent | fix: revert to static homepage (#195) (diff) | |
| download | lphub-a65d6d9127c3fa7f6a8ecaec5d1ffd1f47c2bc98.tar.gz lphub-a65d6d9127c3fa7f6a8ecaec5d1ffd1f47c2bc98.tar.bz2 lphub-a65d6d9127c3fa7f6a8ecaec5d1ffd1f47c2bc98.zip | |
refactor: port to typescript
Diffstat (limited to 'frontend/src/pages/Maps.tsx')
| -rw-r--r-- | frontend/src/pages/Maps.tsx | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/frontend/src/pages/Maps.tsx b/frontend/src/pages/Maps.tsx new file mode 100644 index 0000000..707d865 --- /dev/null +++ b/frontend/src/pages/Maps.tsx | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | import React from 'react'; | ||
| 2 | import { Link, useLocation } from 'react-router-dom'; | ||
| 3 | |||
| 4 | import { PortalIcon, FlagIcon, ChatIcon } from '../images/Images'; | ||
| 5 | import Summary from '../components/Summary'; | ||
| 6 | import Leaderboards from '../components/Leaderboards'; | ||
| 7 | import Discussions from '../components/Discussions'; | ||
| 8 | import ModMenu from '../components/ModMenu'; | ||
| 9 | import { MapDiscussions, MapLeaderboard, MapSummary } from '../types/Map'; | ||
| 10 | import { API } from '../api/Api'; | ||
| 11 | import "../css/Maps.css"; | ||
| 12 | |||
| 13 | interface MapProps { | ||
| 14 | isModerator: boolean; | ||
| 15 | }; | ||
| 16 | |||
| 17 | const Maps: React.FC<MapProps> = ({ isModerator }) => { | ||
| 18 | |||
| 19 | const [selectedRun, setSelectedRun] = React.useState<number>(0); | ||
| 20 | |||
| 21 | const [mapSummaryData, setMapSummaryData] = React.useState<MapSummary | undefined>(undefined); | ||
| 22 | const [mapLeaderboardData, setMapLeaderboardData] = React.useState<MapLeaderboard | undefined>(undefined); | ||
| 23 | const [mapDiscussionsData, setMapDiscussionsData] = React.useState<MapDiscussions | undefined>(undefined) | ||
| 24 | |||
| 25 | |||
| 26 | const [navState, setNavState] = React.useState<number>(0); | ||
| 27 | |||
| 28 | const location = useLocation(); | ||
| 29 | |||
| 30 | const mapID = location.pathname.split("/")[2]; | ||
| 31 | |||
| 32 | const _fetch_map_summary = async () => { | ||
| 33 | const mapSummary = await API.get_map_summary(mapID); | ||
| 34 | setMapSummaryData(mapSummary); | ||
| 35 | }; | ||
| 36 | |||
| 37 | const _fetch_map_leaderboards = async () => { | ||
| 38 | const mapLeaderboards = await API.get_map_leaderboard(mapID); | ||
| 39 | setMapLeaderboardData(mapLeaderboards); | ||
| 40 | }; | ||
| 41 | |||
| 42 | const _fetch_map_discussions = async () => { | ||
| 43 | const mapDiscussions = await API.get_map_discussions(mapID); | ||
| 44 | setMapDiscussionsData(mapDiscussions); | ||
| 45 | }; | ||
| 46 | |||
| 47 | React.useEffect(() => { | ||
| 48 | _fetch_map_summary(); | ||
| 49 | _fetch_map_leaderboards(); | ||
| 50 | _fetch_map_discussions(); | ||
| 51 | }, []); | ||
| 52 | |||
| 53 | if (!mapSummaryData) { | ||
| 54 | return ( | ||
| 55 | <></> | ||
| 56 | ); | ||
| 57 | } | ||
| 58 | |||
| 59 | return ( | ||
| 60 | <> | ||
| 61 | {isModerator && <ModMenu data={mapSummaryData} selectedRun={selectedRun} mapID={mapID} />} | ||
| 62 | |||
| 63 | <div id='background-image'> | ||
| 64 | <img src={mapSummaryData.map.image} alt="" /> | ||
| 65 | </div> | ||
| 66 | <main> | ||
| 67 | <section id='section1' className='summary1'> | ||
| 68 | <div> | ||
| 69 | <Link to="/games"><button className='nav-button' style={{ borderRadius: "20px 0px 0px 20px" }}><i className='triangle'></i><span>Games list</span></button></Link> | ||
| 70 | <Link to={`/games/${!mapSummaryData.map.is_coop ? "1" : "2"}?chapter=${mapSummaryData.map.chapter_name}`}><button className='nav-button' style={{ borderRadius: "0px 20px 20px 0px", marginLeft: "2px" }}><i className='triangle'></i><span>{mapSummaryData.map.chapter_name}</span></button></Link> | ||
| 71 | <br /><span><b>{mapSummaryData.map.map_name}</b></span> | ||
| 72 | </div> | ||
| 73 | |||
| 74 | |||
| 75 | </section> | ||
| 76 | |||
| 77 | <section id='section2' className='summary1'> | ||
| 78 | <button className='nav-button' onClick={() => setNavState(0)}><img src={PortalIcon} alt="" /><span>Summary</span></button> | ||
| 79 | <button className='nav-button' onClick={() => setNavState(1)}><img src={FlagIcon} alt="" /><span>Leaderboards</span></button> | ||
| 80 | <button className='nav-button' onClick={() => setNavState(2)}><img src={ChatIcon} alt="" /><span>Discussions</span></button> | ||
| 81 | </section> | ||
| 82 | |||
| 83 | {navState === 0 && <Summary selectedRun={selectedRun} setSelectedRun={setSelectedRun} data={mapSummaryData} />} | ||
| 84 | {navState === 1 && <Leaderboards data={mapLeaderboardData} />} | ||
| 85 | {navState === 2 && <Discussions data={mapDiscussionsData} isModerator={isModerator} mapID={mapID} onRefresh={() => _fetch_map_discussions()} />} | ||
| 86 | </main> | ||
| 87 | </> | ||
| 88 | ); | ||
| 89 | }; | ||
| 90 | |||
| 91 | export default Maps; | ||