From 6456526cc7f6805e42af94aff332046437a0d87b Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Tue, 20 Aug 2024 19:53:44 +0300 Subject: fix: homepage api call spam (#195) --- frontend/src/components/pages/home.js | 89 +++++++++++++++++------------------ 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/frontend/src/components/pages/home.js b/frontend/src/components/pages/home.js index ba96904..b0cc75f 100644 --- a/frontend/src/components/pages/home.js +++ b/frontend/src/components/pages/home.js @@ -1,20 +1,19 @@ -import React, { useEffect, useRef, useState } from 'react'; -import { useLocation, Link } from "react-router-dom"; +import React, { useEffect, useState } from 'react'; 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 [home, setHome] = React.useState(null); - const [profile, setProfile] = React.useState(null); - const [loading, setLoading] = React.useState(true) - const location = useLocation(); +export default function Homepage({ token }) { + const [profile, setProfile] = useState(null); + const [loading, setLoading] = useState(true) - const [isLoggedIn, setIsLoggedIn] = React.useState(false); - React.useEffect(() => { + const [isLoggedIn, setIsLoggedIn] = useState(false); + + useEffect(() => { + if (!token) { + return; + } try { fetch(`https://lp.ardapektezol.com/api/v1/profile`, { headers: { @@ -35,8 +34,8 @@ export default function Homepage(prop) { } catch (error) { console.log(error) } - - }, [token, profile]); + + }, [token]); useEffect(() => { async function fetchMapImg() { @@ -170,42 +169,42 @@ export default function Homepage(prop) {
{/* Column 1 */} {isLoggedIn ? -
-
-
- Overall rank
- {profile.rankings.overall.rank > 0 ? "#" + profile.rankings.overall.rank : "No rank"} -
-
- 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 + ")" : ""} -
-
- 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 + ")" : ""} +
+
+
+ Overall rank
+ {profile.rankings.overall.rank > 0 ? "#" + profile.rankings.overall.rank : "No rank"} +
+
+ 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 + ")" : ""} +
+
+ 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} + + : null} {isLoggedIn ? -
-
-
-
- Container Ride - Your Record: 4 portals - World Record: 2 portals -
-
-
-
-
-
+
+
+
+
+ Container Ride + Your Record: 4 portals + World Record: 2 portals +
+
+
+
+
+
+
-
-
- : null} + + : null}
-- cgit v1.2.3