From ecf62a1008e84712b7373bb023ca024efbf717e1 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Sun, 15 Oct 2023 12:27:49 +0800 Subject: [PATCH] Homepage optimizations --- src/routes/Home/Home.tsx | 45 +++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index 2044956..3844e42 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -111,8 +111,8 @@ export default function Home() { queryClient.invalidateQueries({ queryKey: ["study_group_list"], }); + requestLocation(); }, 2000); - requestLocation(); return () => clearInterval(interval); }, []); @@ -121,12 +121,10 @@ export default function Home() { let dist = GetDistanceFromUSTP(location.coords); setDist(dist); // Deactivate student status if too far away and still studying - if (dist >= 2 && !map_distance_override && studying) { - if (!stopping_toofar) { - stop_studying.mutate({ - active: false, - }); - } + if (dist >= 2 && !map_distance_override && studying && !stopping_toofar) { + stop_studying.mutate({ + active: false, + }); setStopping(true); } } @@ -382,23 +380,22 @@ export default function Home() { ); } else if (dist && location) { - if (dist <= 1 || map_distance_override) { - if ( - (StudentStatusQuery.isFetching && studying) || - StudentStatusListQuery.isFetching || - StudyGroupQuery.isFetching || - (StudentStatusQuery.isFetching && !studying) || - StudentStatusListGlobalQuery.isFetching || - StudyGroupGlobalQuery.isFetching - ) { - return ( - <> - - - Loading... - - ); - } + if ( + (StudentStatusQuery.isFetching && studying) || + StudentStatusListQuery.isFetching || + StudyGroupQuery.isFetching || + (StudentStatusQuery.isFetching && !studying) || + StudentStatusListGlobalQuery.isFetching || + StudyGroupGlobalQuery.isFetching + ) { + return ( + <> + + + Loading... + + ); + } else if (dist <= 1 || map_distance_override) { return ( <>