From 7b175c44dfcb4ac140a94ebe6c1cd4a5b11caa69 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Fri, 13 Oct 2023 12:45:55 +0800 Subject: [PATCH] Added stop-gaps to help with refreshing queries on slower connections and increased refresh interval for homepage from 15 seconds to 10 seconds --- src/routes/CreateGroup/CreateGroup.tsx | 8 ++++++-- src/routes/Home/Home.tsx | 4 ++-- src/routes/StartStudying/StartStudying.tsx | 7 ++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/routes/CreateGroup/CreateGroup.tsx b/src/routes/CreateGroup/CreateGroup.tsx index 296b5d8..904d472 100644 --- a/src/routes/CreateGroup/CreateGroup.tsx +++ b/src/routes/CreateGroup/CreateGroup.tsx @@ -43,7 +43,6 @@ export default function CreateGroup({ route }: any) { onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["user"] }); queryClient.invalidateQueries({ queryKey: ["user_status"] }); - queryClient.invalidateQueries({ queryKey: ["study_group_list"] }); student_status_patch.mutate({ study_group: name, }); @@ -75,13 +74,18 @@ export default function CreateGroup({ route }: any) { onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["user"] }); queryClient.invalidateQueries({ queryKey: ["user_status"] }); + queryClient.invalidateQueries({ queryKey: ["user_status_list"] }); + queryClient.invalidateQueries({ queryKey: ["study_group_list"] }); toast.show(`Joined group ${name} successfully`, { type: "success", placement: "top", duration: 2000, animationType: "slide-in", }); - navigation.navigate("Home"); + // Set a delay before going back to homepage to hopefully let the queries refresh in time + setTimeout(() => { + navigation.navigate("Home"); + }, 200); }, onError: (error: Error) => { toast.show(String(error), { diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index 81c4ec9..52dcd3f 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -93,11 +93,11 @@ export default function Home() { } } - // Refresh every 15 seconds + // Refresh every 10 seconds useEffect(() => { const interval = setInterval(() => { requestLocation(); - }, 15000); + }, 10000); return () => clearInterval(interval); }); diff --git a/src/routes/StartStudying/StartStudying.tsx b/src/routes/StartStudying/StartStudying.tsx index fdeeced..1656482 100644 --- a/src/routes/StartStudying/StartStudying.tsx +++ b/src/routes/StartStudying/StartStudying.tsx @@ -79,13 +79,18 @@ export default function StartStudying({ route }: any) { onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["user"] }); queryClient.invalidateQueries({ queryKey: ["user_status"] }); + queryClient.invalidateQueries({ queryKey: ["user_status_list"] }); + queryClient.invalidateQueries({ queryKey: ["study_group_list"] }); toast.show("You are now studying \n" + selected_subject, { type: "success", placement: "top", duration: 2000, animationType: "slide-in", }); - navigation.navigate("Home"); + // Set a delay before going back to homepage to hopefully let the queries refresh in time + setTimeout(() => { + navigation.navigate("Home"); + }, 200); }, onError: (error: Error) => { toast.show(String(error), {