From af2885278b50365b1ff19aaa55d1ebdacdb1d478 Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Tue, 2 Apr 2024 17:57:04 +0200 Subject: [PATCH] Arreglado el cambio de modo en Stats --- webapp/src/pages/Stats/Stats.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/webapp/src/pages/Stats/Stats.js b/webapp/src/pages/Stats/Stats.js index 34103fe8..68f16d43 100644 --- a/webapp/src/pages/Stats/Stats.js +++ b/webapp/src/pages/Stats/Stats.js @@ -23,9 +23,9 @@ const Stats = () => { const [error, setError] = useState(null); const [fetched, setFetched] = useState(false); - const fetchStats = () => { + const fetchStats = (mode) => { setIsLoading(true); - fetch(gatewayUrl + `/stats?user=${username}&gamemode=${gamemode}`) + fetch(gatewayUrl + `/stats?user=${username}&gamemode=${mode}`) .then((response) => response.json()) .then((data) => { setStats(data); @@ -42,7 +42,7 @@ const Stats = () => { useEffect(() => { if (!fetched) { - fetchStats(); + fetchStats(gamemode); setFetched(true); } // eslint-disable-next-line @@ -52,14 +52,16 @@ const Stats = () => { setUsername(event.target.value); }; - const handleGamemodeChange = (mode) => { + const handleGamemodeChange = async (mode) => { + if (mode === gamemode) return; + setGamemode(mode); - // Llama a fetchStats() para actualizar las estadísticas cuando se cambia el modo de juego - fetchStats(); + fetchStats(mode); }; + const handleSearch = () => { - fetchStats(); + fetchStats(gamemode); }; const getModeName = () => {