import React from "react"; import { Link, useLocation, useNavigate } from "react-router-dom"; import { Helmet } from "react-helmet"; import { SteamIcon, TwitchIcon, YouTubeIcon, PortalIcon, FlagIcon, StatisticsIcon, SortIcon, ThreedotIcon, DownloadIcon, HistoryIcon, } from "@images/Images"; import { UserProfile } from "@customTypes/Profile"; import { Game, GameChapters } from "@customTypes/Game"; import { Map } from "@customTypes/Map"; import { API } from "@api/Api"; import { ticks_to_time } from "@utils/Time"; import "@css/Profile.css"; import useMessage from "@hooks/UseMessage"; interface UserProps { profile?: UserProfile; token?: string; gameData: Game[]; } const User: React.FC = ({ token, profile, gameData }) => { const { message, MessageDialogComponent } = useMessage(); const [user, setUser] = React.useState(undefined); 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 [chapter, setChapter] = React.useState("0"); const [chapterData, setChapterData] = React.useState( null ); const [maps, setMaps] = React.useState([]); const location = useLocation(); const navigate = useNavigate(); const _fetch_user = React.useCallback(async () => { const userID = location.pathname.split("/")[2]; if (token && profile && profile.profile && profile.steam_id === userID) { navigate("/profile"); return; } const userData = await API.get_user(userID); setUser(userData); }, [location.pathname, token, profile, navigate]); const _get_game_chapters = React.useCallback(async () => { if (game !== "0") { const gameChapters = await API.get_games_chapters(game); setChapterData(gameChapters); } else { setPageMax(Math.ceil(user!.records.length / 20)); setPageNumber(1); } }, [game, user]); const _get_game_maps = React.useCallback(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); } }, [chapter, game]); React.useEffect(() => { _fetch_user(); }, [location, _fetch_user]); React.useEffect(() => { if (user) { _get_game_chapters(); } }, [user, game, location, _get_game_chapters]); React.useEffect(() => { if (user && game !== "0") { _get_game_maps(); } }, [user, game, chapter, location, _get_game_maps]); if (!user) { return <>; } return (
LPHUB | {user.user_name} {MessageDialogComponent}
profile-image
{user.user_name}
{user.country_code === "XX" ? ( "" ) : ( {user.country_code} )}
{user.titles.map(e => ( {e.name} ))}
{user.links.steam === "-" ? ( "" ) : ( Steam )} {user.links.twitch === "-" ? ( "" ) : ( Twitch )} {user.links.youtube === "-" ? ( "" ) : ( Youtube )} {user.links.p2sr === "-" ? ( "" ) : ( P2SR )}
Overall {user.rankings.overall.rank === 0 ? "N/A " : "#" + user.rankings.overall.rank + " "} ({user.rankings.overall.completion_count}/ {user.rankings.overall.completion_total})
Singleplayer {user.rankings.singleplayer.rank === 0 ? "N/A " : "#" + user.rankings.singleplayer.rank + " "} ({user.rankings.singleplayer.completion_count}/ {user.rankings.singleplayer.completion_total})
Cooperative {user.rankings.cooperative.rank === 0 ? "N/A " : "#" + user.rankings.cooperative.rank + " "} ({user.rankings.cooperative.completion_count}/ {user.rankings.cooperative.completion_total})
{gameData === null ? ( ) : ( )} {game === "0" ? ( ) : chapterData === null ? ( ) : ( )}
Map Name Portals WRΔ Time Rank Date
{pageNumber}/{pageMax}

{game === "0" ? ( user.records .sort((a, b) => a.map_id - b.map_id) .map((r, index) => Math.ceil((index + 1) / 20) === pageNumber ? ( {i === 0 && r.scores.length > 1 ? ( ) : ( "" )} ))} ) : ( "" ) ) ) : maps ? ( maps .filter(e => e.is_disabled === false) .sort((a, b) => a.id - b.id) .map((r, index) => { if (Math.ceil((index + 1) / 20) === pageNumber) { let record = user.records.find(e => e.map_id === r.id); return record === undefined ? ( ) : ( {i === 0 && record!.scores.length > 1 ? ( ) : ( "" )} ))} ); } else { return null; } }) ) : ( <>{console.warn(maps)} )}
); }; export default User;