From 4caf86c6be7deaab2321aae5b3a8fbbe19e68cfa Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Fri, 13 Oct 2023 14:28:22 +0800 Subject: [PATCH] Fixed map elements not rendering on first open when on poor network conditions --- src/routes/Home/Home.tsx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index 27282cf..66a5727 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -91,25 +91,30 @@ export default function Home() { newLocation.coords.longitude !== location.coords.longitude ) { setLocation(newLocation); - DistanceHandler(newLocation); + await DistanceHandler(newLocation); } } } } - // Refresh every 10 seconds + // Refresh when screen loads & every 10 seconds + requestLocation(); useEffect(() => { const interval = setInterval(() => { requestLocation(); }, 10000); - - return () => clearInterval(interval); - }); - - // Refresh when screen loads - requestLocation(); - useEffect(() => { + setTimeout(() => { + queryClient.invalidateQueries({ queryKey: ["user"] }); + queryClient.invalidateQueries({ queryKey: ["user_status"] }); + queryClient.invalidateQueries({ + queryKey: ["user_status_list"], + }); + queryClient.invalidateQueries({ + queryKey: ["study_group_list"], + }); + }, 2000); requestLocation(); + return () => clearInterval(interval); }, []); async function DistanceHandler(location: RawLocationType) {