From 78feb11e4da4f497fa44b914b9c51eef7e22c708 Mon Sep 17 00:00:00 2001 From: Li Bao Date: Mon, 16 Sep 2024 20:11:17 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20avoid=20sending=20HTTP=20?= =?UTF-8?q?request=20to=20/contest-records/real-time-rank=20API=20when=20u?= =?UTF-8?q?ser=20is=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/charts/RealTimeRankChart.jsx | 2 -- .../src/pages/Predicted/PredictedRecords.jsx | 21 +++++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/client/src/components/charts/RealTimeRankChart.jsx b/client/src/components/charts/RealTimeRankChart.jsx index 95b9475..e5d135f 100644 --- a/client/src/components/charts/RealTimeRankChart.jsx +++ b/client/src/components/charts/RealTimeRankChart.jsx @@ -1,8 +1,6 @@ import ReactEcharts from "echarts-for-react"; const RealTimeRankChart = ({ user, rankList }) => { - if (!rankList) return null; - const realTimeRank = [["Minute", "Username", "Rank"]]; for (let j = 1; j <= rankList.length; j++) { realTimeRank.push([j, user.username, rankList[j - 1]]); diff --git a/client/src/pages/Predicted/PredictedRecords.jsx b/client/src/pages/Predicted/PredictedRecords.jsx index c3f8195..bc677b1 100644 --- a/client/src/pages/Predicted/PredictedRecords.jsx +++ b/client/src/pages/Predicted/PredictedRecords.jsx @@ -230,13 +230,15 @@ const PredictedRecords = () => { // console.log(`user=${user} ${user?.username} ${user?.data_region}`); const { data: rankData } = useSWR( - [ - `${baseUrl}/contest-records/real-time-rank`, - JSON.stringify({ - contest_name: titleSlug, - user: user, - }), - ], + user + ? [ + `${baseUrl}/contest-records/real-time-rank`, + JSON.stringify({ + contest_name: titleSlug, + user: user, + }), + ] + : null, ([url, body]) => fetch(url, { method: "POST", @@ -246,6 +248,7 @@ const PredictedRecords = () => { { revalidateOnFocus: false } ); const rankList = rankData?.real_time_rank; + // console.log(`rankData=${rankData} rankList=${rankList} ${rankList?.length} ${!rankList}`) if (!predictedRecords || isLoading) return ( @@ -304,8 +307,8 @@ const PredictedRecords = () => {