From b0345dc2b730114277243508c4041af4c6b43910 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Sun, 1 Oct 2023 15:56:01 +0800 Subject: [PATCH] Code cleanup --- src/components/BackgroundTask/BackgroundTask.tsx | 9 +++------ src/components/DrawerSettings/CustomDrawerContent.tsx | 8 +++++--- src/routes/ConversationPage/ConversationPage.tsx | 8 -------- src/routes/Home/Home.tsx | 6 +++--- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/components/BackgroundTask/BackgroundTask.tsx b/src/components/BackgroundTask/BackgroundTask.tsx index 21f3ebd..840319c 100644 --- a/src/components/BackgroundTask/BackgroundTask.tsx +++ b/src/components/BackgroundTask/BackgroundTask.tsx @@ -3,11 +3,7 @@ import { View } from "react-native"; import * as BackgroundFetch from "expo-background-fetch"; import * as TaskManager from "expo-task-manager"; import * as Notifications from "expo-notifications"; -import { - GetStudentStatus, - GetStudyGroupListFiltered, - GetUserInfo, -} from "../Api/Api"; +import { GetStudentStatus, GetStudyGroupListFiltered } from "../Api/Api"; import { StudyGroupType } from "../../interfaces/Interfaces"; const FETCH_STUDENT_STATUS = "STUDENT_STATUS_TASK"; @@ -47,6 +43,7 @@ TaskManager.defineTask(FETCH_STUDENT_STATUS, async () => { }); const BackgroundComponent = () => { + const notification_debug = true; const [isRegistered, setIsRegistered] = React.useState(false); const [status, setStatus] = React.useState(); const checkStatusAsync = async () => { @@ -64,7 +61,7 @@ const BackgroundComponent = () => { await checkStatusAsync(); if (!isRegistered) { await BackgroundFetch.registerTaskAsync(FETCH_STUDENT_STATUS, { - minimumInterval: 5, // seconds, + minimumInterval: notification_debug ? 5 : 60 * 3, // Check every 5 seconds in dev & every 3 minutes in production builds }); console.log("Task registered"); } else { diff --git a/src/components/DrawerSettings/CustomDrawerContent.tsx b/src/components/DrawerSettings/CustomDrawerContent.tsx index 0d91bd4..1b31ad8 100644 --- a/src/components/DrawerSettings/CustomDrawerContent.tsx +++ b/src/components/DrawerSettings/CustomDrawerContent.tsx @@ -27,12 +27,12 @@ import { PatchStudentStatus } from "../Api/Api"; import { useToast } from "react-native-toast-notifications"; export default function CustomDrawerContent(props: {}) { + const debug = true; const navigation = useNavigation(); const status = useSelector((state: RootState) => state.status); const dispatch = useDispatch(); const queryClient = useQueryClient(); const toast = useToast(); - const debug_disable_clear_on_logout = true; const stop_studying_logout = useMutation({ mutationFn: async (info: StudentStatusPatchType) => { const data = await PatchStudentStatus(info); @@ -78,7 +78,8 @@ export default function CustomDrawerContent(props: {}) { { - if (debug_disable_clear_on_logout) { + // We don't clear student statuses when logging out on debug + if (!debug) { queryClient.clear(); dispatch(logout()); await AsyncStorage.clear(); @@ -141,7 +142,8 @@ export default function CustomDrawerContent(props: {}) { { - if (debug_disable_clear_on_logout) { + // We don't clear student statuses when logging out on debug + if (!debug) { queryClient.clear(); dispatch(logout()); await AsyncStorage.clear(); diff --git a/src/routes/ConversationPage/ConversationPage.tsx b/src/routes/ConversationPage/ConversationPage.tsx index e7ce17c..edc8982 100644 --- a/src/routes/ConversationPage/ConversationPage.tsx +++ b/src/routes/ConversationPage/ConversationPage.tsx @@ -34,14 +34,6 @@ import { useToast } from "react-native-toast-notifications"; import { useQueryClient } from "@tanstack/react-query"; import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer"; -type ConversationType = { - id: number; - user: string; - message_content: string; - study_group: string; - color: string; -}; - export default function ConversationPage() { const toast = useToast(); // Student Status diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index 331b6ef..8e3cbd7 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -38,7 +38,7 @@ import CaretUpIcon from "../../icons/CaretUpIcon/CaretUpIcon"; export default function Home() { // Switch this condition to see the main map when debugging - const map_debug = true; + const map_distance_override = true; const navigation = useNavigation(); const [location, setLocation] = useState(null); const [dist, setDist] = useState(null); @@ -100,7 +100,7 @@ export default function Home() { let dist = GetDistanceFromUSTP(location.coords); setDist(dist); // Deactivate student status if too far away - if (dist >= 2 && !map_debug) + if (dist >= 2 && !map_distance_override) stop_studying.mutate({ active: false, }); @@ -345,7 +345,7 @@ export default function Home() { function CustomMap() { if (dist && location) { - if (dist <= 2 || map_debug) { + if (dist <= 2 || map_distance_override) { return ( <>