From a7c282ca348c1e8e60559e5c064caee28ba11eec Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Wed, 9 Oct 2024 16:34:12 +0300 Subject: refactor: so much shit --- frontend/src/pages/Homepage.tsx | 2 +- frontend/src/pages/Maplist.tsx | 5 +- frontend/src/pages/Maps.tsx | 14 ++-- frontend/src/pages/Profile.tsx | 131 +++++++++++++++-------------------- frontend/src/pages/Rankings.tsx | 65 ++++++++---------- frontend/src/pages/Rules.tsx | 4 +- frontend/src/pages/User.tsx | 146 +++++++++++++++++----------------------- 7 files changed, 153 insertions(+), 214 deletions(-) (limited to 'frontend/src/pages') diff --git a/frontend/src/pages/Homepage.tsx b/frontend/src/pages/Homepage.tsx index 8e5bb4b..8c1cd48 100644 --- a/frontend/src/pages/Homepage.tsx +++ b/frontend/src/pages/Homepage.tsx @@ -7,7 +7,7 @@ const Homepage: React.FC = () => {

-

lphubWelcome to Least Portals Hub!

+

Welcome to Least Portals Hub!

At the moment, LPHUB is in beta state. This means that the site has only the core functionalities enabled for providing both collaborative information and competitive leaderboards.

The website should feel intuitive to navigate around. For any type of feedback, reach us at LPHUB Discord server.

By using LPHUB, you agree that you have read the 'Leaderboard Rules' and the 'About LPHUB' pages.

diff --git a/frontend/src/pages/Maplist.tsx b/frontend/src/pages/Maplist.tsx index 5d0c852..9526d18 100644 --- a/frontend/src/pages/Maplist.tsx +++ b/frontend/src/pages/Maplist.tsx @@ -64,6 +64,7 @@ const Maplist: React.FC = () => { // console.log(foundGame) if (foundGame) { setGame(foundGame); + setLoad(false); } }; @@ -73,9 +74,9 @@ const Maplist: React.FC = () => { setNumChapters(games_chapters.chapters.length); } + setLoad(true); _fetch_game(); _fetch_game_chapters(); - setLoad(true); }, []); useEffect(() => { @@ -96,7 +97,7 @@ const Maplist: React.FC = () => {
- {!load ? ( + {load ? (
) : (
diff --git a/frontend/src/pages/Maps.tsx b/frontend/src/pages/Maps.tsx index 62fc3cc..13ee4d9 100644 --- a/frontend/src/pages/Maps.tsx +++ b/frontend/src/pages/Maps.tsx @@ -7,18 +7,16 @@ import Leaderboards from '../components/Leaderboards'; import Discussions from '../components/Discussions'; import ModMenu from '../components/ModMenu'; import { MapDiscussions, MapLeaderboard, MapSummary } from '../types/Map'; -import { UserProfile } from '../types/Profile'; import { API } from '../api/Api'; import "../css/Maps.css"; import Loading from '../components/Loading'; interface MapProps { - profile?: UserProfile; + token?: string; isModerator: boolean; - onUploadRun: (mapID: number) => void; }; -const Maps: React.FC = ({ profile, isModerator, onUploadRun }) => { +const Maps: React.FC = ({ token, isModerator }) => { const [selectedRun, setSelectedRun] = React.useState(0); @@ -39,7 +37,8 @@ const Maps: React.FC = ({ profile, isModerator, onUploadRun }) => { const _fetch_map_leaderboards = async () => { const mapLeaderboards = await API.get_map_leaderboard(mapID); - console.log(mapLeaderboards?.records[0]); + console.log("lbs:") + console.log(mapLeaderboards); setMapLeaderboardData(mapLeaderboards); }; @@ -77,7 +76,7 @@ const Maps: React.FC = ({ profile, isModerator, onUploadRun }) => { return ( <> - {isModerator && } + {isModerator && }
@@ -88,7 +87,6 @@ const Maps: React.FC = ({ profile, isModerator, onUploadRun }) => {
{mapSummaryData.map.map_name} - {profile && }
@@ -100,7 +98,7 @@ const Maps: React.FC = ({ profile, isModerator, onUploadRun }) => { {navState === 0 && } {navState === 1 && } - {navState === 2 && _fetch_map_discussions()} />} + {navState === 2 && _fetch_map_discussions()} />}
); diff --git a/frontend/src/pages/Profile.tsx b/frontend/src/pages/Profile.tsx index 8eec23c..e20d930 100644 --- a/frontend/src/pages/Profile.tsx +++ b/frontend/src/pages/Profile.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { useLocation, useNavigate } from 'react-router-dom'; +import { Link, useLocation, useNavigate } from 'react-router-dom'; import { SteamIcon, TwitchIcon, YouTubeIcon, PortalIcon, FlagIcon, StatisticsIcon, SortIcon, ThreedotIcon, DownloadIcon, HistoryIcon } from '../images/Images'; import { UserProfile } from '../types/Profile'; @@ -7,104 +7,74 @@ import { Game, GameChapters } from '../types/Game'; import { Map } from '../types/Map'; import { ticks_to_time } from '../utils/Time'; import "../css/Profile.css"; +import { API } from '../api/Api'; interface ProfileProps { profile?: UserProfile; + token?: string; + gameData: Game[]; } -const Profile: React.FC = ({ profile }) => { - - - const location = useLocation(); - const navigate = useNavigate(); - - React.useEffect(() => { - if (!profile) { - navigate("/"); - }; - }, [profile]); +const Profile: React.FC = ({ profile, token, gameData }) => { const [navState, setNavState] = React.useState(0); const [pageNumber, setPageNumber] = React.useState(1); const [pageMax, setPageMax] = React.useState(0); const [game, setGame] = React.useState("0") - const [gameData, setGameData] = React.useState([]); const [chapter, setChapter] = React.useState("0") const [chapterData, setChapterData] = React.useState(null); const [maps, setMaps] = React.useState([]); - function NavClick() { - if (profile) { - const btn = document.querySelectorAll("#section2 button"); - btn.forEach((e) => { (e as HTMLElement).style.backgroundColor = "#2b2e46" }); - (btn[navState] as HTMLElement).style.backgroundColor = "#202232"; + const navigate = useNavigate(); - document.querySelectorAll("section").forEach((e, i) => i >= 2 ? e.style.display = "none" : "") - if (navState === 0) { document.querySelectorAll(".profile1").forEach((e) => { (e as HTMLElement).style.display = "block" }); } - if (navState === 1) { document.querySelectorAll(".profile2").forEach((e) => { (e as HTMLElement).style.display = "block" }); } + const _update_profile = () => { + if (token) { + API.post_profile(token).then(() => navigate(0)); } - } + }; - function UpdateProfile() { - fetch(`https://lp.ardapektezol.com/api/v1/profile`, { - method: 'POST', - headers: { Authorization: "" } - }).then(r => r.json()) - .then(d => d.success ? window.alert("profile updated") : window.alert(`Error: ${d.message}`)) - } + const _get_game_chapters = async () => { + if (game && game !== "0") { + const gameChapters = await API.get_games_chapters(game); + setChapterData(gameChapters); + } else if (game && game === "0") { + setPageMax(Math.ceil(profile!.records.length / 20)); + setPageNumber(1); + } + }; - React.useEffect(() => { - if (profile) { - fetch("https://lp.ardapektezol.com/api/v1/games") - .then(r => r.json()) - .then(d => { - setGameData(d.data) - setGame("0") - }) + const _get_game_maps = async () => { + if (chapter === "0") { + const gameMaps = await API.get_game_maps(game); + setMaps(gameMaps); + setPageMax(Math.ceil(gameMaps.length / 20)); + setPageNumber(1); + } else { + const gameChapters = await API.get_chapters(chapter); + setMaps(gameChapters.maps); + setPageMax(Math.ceil(gameChapters.maps.length / 20)); + setPageNumber(1); } - }, [profile, location]); + }; + + React.useEffect(() => { + if (!profile) { + navigate("/"); + }; + }, [profile]); React.useEffect(() => { if (profile) { - if (game && game !== "0") { - fetch(`https://lp.ardapektezol.com/api/v1/games/${game}`) - .then(r => r.json()) - .then(d => { - setChapterData(d.data) - setChapter("0"); - // (document.querySelector('#select-chapter') as HTMLInputElement).value = "0" - }) - - } else if (game && game === "0") { - setPageMax(Math.ceil(profile.records.length / 20)) - setPageNumber(1) - } + _get_game_chapters(); } - }, [profile, game, location]); + }, [profile, game]); React.useEffect(() => { - if (game !== "0") { - if (chapter === "0") { - fetch(`https://lp.ardapektezol.com/api/v1/games/${game}/maps`) - .then(r => r.json()) - .then(d => { - setMaps(d.data.maps); - setPageMax(Math.ceil(d.data.maps.length / 20)) - setPageNumber(1) - }) - } else { - fetch(`https://lp.ardapektezol.com/api/v1/chapters/${chapter}`) - .then(r => r.json()) - .then(d => { - setMaps(d.data.maps); - setPageMax(Math.ceil(d.data.maps.length / 20)) - setPageNumber(1) - }) - - } + if (profile && game !== "0") { + _get_game_maps(); } - }, [game, chapter, chapterData]) + }, [profile, game, chapter, chapterData]) if (!profile) { return ( @@ -118,7 +88,7 @@ const Profile: React.FC = ({ profile }) => { {profile.profile ? ( -
UpdateProfile()}> +
profile-image Refresh
@@ -187,7 +157,14 @@ const Profile: React.FC = ({ profile }) => { {gameData === null ? : error :