From 83d2243c65bf5fce5c75ef3753595d38f4d545d5 Mon Sep 17 00:00:00 2001 From: Wolfboy248 <121288977+Wolfboy248@users.noreply.github.com> Date: Sat, 13 Jul 2024 00:15:58 +0200 Subject: feat: fixes, styles, partial homepage implementation and maplist header loader (#188) --- frontend/src/components/pages/home.js | 125 ++++++++++++++++++++++++++-------- 1 file changed, 97 insertions(+), 28 deletions(-) (limited to 'frontend/src/components/pages/home.js') diff --git a/frontend/src/components/pages/home.js b/frontend/src/components/pages/home.js index c1477ab..55e58a8 100644 --- a/frontend/src/components/pages/home.js +++ b/frontend/src/components/pages/home.js @@ -4,14 +4,45 @@ import { useLocation, Link } from "react-router-dom"; import "./home.css" import News from '../news'; import Record from '../record'; +import Login from '../login'; export default function Homepage(prop) { - const {token, setToken} = prop + const { token, setToken } = prop const [home, setHome] = React.useState(null); + const [profile, setProfile] = React.useState(null); + const [loading, setLoading] = React.useState(true) const location = useLocation(); + const [isLoggedIn, setIsLoggedIn] = React.useState(false); + React.useEffect(() => { + try { + fetch(`https://lp.ardapektezol.com/api/v1/profile`, { + headers: { + 'Content-Type': 'application/json', + Authorization: token + } + }) + .then(r => r.json()) + .then(d => setProfile(d.data)) + .then(d => { + if (profile != null) { + setIsLoggedIn(true) + } + }) + .then(d => { + setLoading(false) + }) + } catch (error) { + console.log(error) + } + + }, [token, profile]); + useEffect(() => { async function fetchMapImg() { + if (!isLoggedIn) { + return; + } try { const response = await fetch("https://lp.ardapektezol.com/api/v1/games", { headers: { @@ -23,11 +54,11 @@ export default function Homepage(prop) { const recommendedMapImg = document.querySelector("#recommendedMapImg"); - recommendedMapImg.src = `${data.data[0].image}` + recommendedMapImg.style.backgroundImage = `url(${data.data[0].image})` const column1 = document.querySelector("#column1"); const column2 = document.querySelector("#column2"); - + column2.style.height = column1.clientHeight + "px"; } catch (error) { console.log(error) @@ -115,41 +146,57 @@ export default function Homepage(prop) { }, ] + if (loading) { + return ( + + + ) + } + return ( - - Welcome back, - Krzyhau + + Home + {isLoggedIn ? + + Welcome back, + + Wolfboy248 + + : null} - + {/* Column 1 */} + {isLoggedIn ? - + - Overall rank - #69 + Overall rank + {profile.rankings.overall.rank > 0 ? "#" + profile.rankings.overall.rank : "No rank"} - Singleplayer - #10 (60/62) + Singleplayer + {profile.rankings.singleplayer.rank > 0 ? "#" + profile.rankings.singleplayer.rank : "No rank"} {profile.rankings.singleplayer.rank > 0 ? "(" + profile.rankings.singleplayer.completion_count + "/" + profile.rankings.singleplayer.completion_total + ")" : ""} - Overall rank - #69 (13/37) + Cooperative rank + {profile.rankings.cooperative.rank > 0 ? "#" + profile.rankings.cooperative.rank : "No rank"} {profile.rankings.cooperative.rank > 0 ? "(" + profile.rankings.cooperative.completion_count + "/" + profile.rankings.cooperative.completion_total + ")" : ""} + : null} + {isLoggedIn ? - - - - Container Ride - Your Record: 4 portals - World Record: 2 portals + + + + Container Ride + Your Record: 4 portals + World Record: 2 portals - + @@ -158,17 +205,39 @@ export default function Homepage(prop) { - + : null} + Place - Runner + Runner Portals Time Date - + + + + + + + + + + + + + + + + + + + + + + @@ -180,9 +249,9 @@ export default function Homepage(prop) { {/* Column 2 */} - + - + {newsList.map((newsList, index) => ( ))} @@ -190,9 +259,9 @@ export default function Homepage(prop) { - - + + ) } \ No newline at end of file -- cgit v1.2.3