Reverted query invalidation on mount in homepage as it was causing performance issues

This commit is contained in:
Keannu Bernasol 2023-10-14 10:35:28 +08:00
parent 4caf86c6be
commit a11ff2ee6f

View file

@ -97,34 +97,28 @@ export default function Home() {
} }
} }
// Refresh when screen loads & every 10 seconds // Refresh every 10 seconds
requestLocation(); requestLocation();
useEffect(() => { useEffect(() => {
const interval = setInterval(() => { const interval = setInterval(() => {
requestLocation(); requestLocation();
}, 10000); }, 10000);
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); return () => clearInterval(interval);
}, []); }, []);
const [stopping_toofar, setStopping] = useState(false);
async function DistanceHandler(location: RawLocationType) { async function DistanceHandler(location: RawLocationType) {
let dist = GetDistanceFromUSTP(location.coords); let dist = GetDistanceFromUSTP(location.coords);
setDist(dist); setDist(dist);
// Deactivate student status if too far away and still studying // Deactivate student status if too far away and still studying
if (dist >= 2 && !map_distance_override && studying) if (dist >= 2 && !map_distance_override && studying) {
stop_studying.mutate({ if (!stopping_toofar) {
active: false, stop_studying.mutate({
}); active: false,
});
}
setStopping(true);
}
setLocationFetched(true); setLocationFetched(true);
} }
@ -196,6 +190,9 @@ export default function Home() {
}, 500); }, 500);
setStudyGroups([]); setStudyGroups([]);
setStudying(false); setStudying(false);
if (stopping_toofar) {
setStopping(false);
}
}, },
onError: (error: Error) => { onError: (error: Error) => {
toast.show(String(error), { toast.show(String(error), {