From 68778cea7aa23745b95c6615e57d18e62e0aa380 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Wed, 20 Sep 2023 21:16:54 +0800 Subject: [PATCH] Code cleanup for multiple pages and components --- .../CustomMapCallout/CustomMapCallout.tsx | 14 +++++++------- src/routes/Home/Home.tsx | 12 +++++++++--- src/routes/StartStudying/StartStudying.tsx | 3 ++- src/routes/SubjectsPage/SubjectsPage.tsx | 3 ++- src/routes/UserInfoPage/UserInfoPage.tsx | 3 ++- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/components/CustomMapCallout/CustomMapCallout.tsx b/src/components/CustomMapCallout/CustomMapCallout.tsx index 23661e3..6184c9a 100644 --- a/src/components/CustomMapCallout/CustomMapCallout.tsx +++ b/src/components/CustomMapCallout/CustomMapCallout.tsx @@ -1,26 +1,26 @@ import { Callout } from "react-native-maps"; -import { RawLocationType } from "../../interfaces/Interfaces"; +import { LocationType, RawLocationType } from "../../interfaces/Interfaces"; import styles from "../../styles"; import { Text } from "react-native"; // Map popup for user's location type props = { - location: RawLocationType; + location: LocationType; studying: boolean; subject?: string; }; export default function CustomMapCallout(props: props) { let { location, studying, subject } = props; - if (location && location.coords) { + if (location && location.latitude && location.longitude) { if (studying) { return ( You are here {"\n"} - X: {Math.round(location.coords.longitude) + "\n"} - Z: {Math.round(location.coords.latitude) + "\n"} + X: {Math.round(location.longitude) + "\n"} + Z: {Math.round(location.latitude) + "\n"} Studying: {subject} @@ -30,8 +30,8 @@ export default function CustomMapCallout(props: props) { You are here {"\n"} - X: {Math.round(location.coords.longitude) + "\n"} - Z: {Math.round(location.coords.latitude)} + X: {Math.round(location.longitude) + "\n"} + Z: {Math.round(location.latitude)} ); diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index c8f9718..3a0317a 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -44,7 +44,7 @@ import GetDistanceFromUSTP from "../../components/GetDistance/GetDistanceFromUST export default function Home() { // Switch this condition to see the main map when debugging - const map_debug = false; + const map_debug = true; const navigation = useNavigation(); const [location, setLocation] = useState(null); const [dist, setDist] = useState(null); @@ -119,6 +119,7 @@ export default function Home() { const [studying, setStudying] = useState(false); const [subject, setSubject] = useState(""); const [buttonLabel, setButtonLabel] = useState("Start studying"); + const [student_status, setStudentStatus] = useState(); const StudentStatus = useQuery({ queryKey: ["user_status"], queryFn: async () => { @@ -140,6 +141,8 @@ export default function Home() { } else if (data[1].active == false) { setButtonLabel("Start Studying"); } + setStudentStatus(data[1]); + console.log(student_status); }, onError: (error: Error) => { toast.show(String(error), { @@ -373,7 +376,7 @@ export default function Home() { latitude: location.coords.latitude, longitude: location.coords.longitude, }} - draggable + draggable={student_status?.active} onDragEnd={(e) => { const newLocation = e.nativeEvent.coordinate; const distance = GetDistance( @@ -402,7 +405,10 @@ export default function Home() { pinColor={colors.primary_1} > diff --git a/src/routes/StartStudying/StartStudying.tsx b/src/routes/StartStudying/StartStudying.tsx index 9f420d2..2aa8677 100644 --- a/src/routes/StartStudying/StartStudying.tsx +++ b/src/routes/StartStudying/StartStudying.tsx @@ -8,6 +8,7 @@ import { RootDrawerParamList, StudentStatusType, StudentStatusReturnType, + StudentStatusPatchType, } from "../../interfaces/Interfaces"; import Button from "../../components/Button/Button"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; @@ -61,7 +62,7 @@ export default function StartStudying({ route }: any) { }); const mutation = useMutation({ - mutationFn: async (info: StudentStatusType) => { + mutationFn: async (info: StudentStatusPatchType) => { const data = await PatchStudentStatus(info); if (data[0] == false) { return Promise.reject(new Error(JSON.stringify(data[1]))); diff --git a/src/routes/SubjectsPage/SubjectsPage.tsx b/src/routes/SubjectsPage/SubjectsPage.tsx index 76c841d..cfee8f7 100644 --- a/src/routes/SubjectsPage/SubjectsPage.tsx +++ b/src/routes/SubjectsPage/SubjectsPage.tsx @@ -9,6 +9,7 @@ import { OptionType, StudentStatusType, PatchUserInfoType, + StudentStatusPatchType, } from "../../interfaces/Interfaces"; import Button from "../../components/Button/Button"; import { Image } from "react-native"; @@ -33,7 +34,7 @@ export default function SubjectsPage() { // Student Status const studentstatus_mutation = useMutation({ - mutationFn: async (info: StudentStatusType) => { + mutationFn: async (info: StudentStatusPatchType) => { const data = await PatchStudentStatus(info); if (data[0] != true) { return Promise.reject(new Error()); diff --git a/src/routes/UserInfoPage/UserInfoPage.tsx b/src/routes/UserInfoPage/UserInfoPage.tsx index 512ea89..5d8a49b 100644 --- a/src/routes/UserInfoPage/UserInfoPage.tsx +++ b/src/routes/UserInfoPage/UserInfoPage.tsx @@ -18,6 +18,7 @@ import { OptionType, StudentStatusType, PatchUserInfoType, + StudentStatusPatchType, } from "../../interfaces/Interfaces"; import Button from "../../components/Button/Button"; import { Image } from "react-native"; @@ -50,7 +51,7 @@ export default function UserInfoPage() { // Student Status const studentstatus_mutation = useMutation({ - mutationFn: async (info: StudentStatusType) => { + mutationFn: async (info: StudentStatusPatchType) => { const data = await PatchStudentStatus(info); if (data[0] != true) { return Promise.reject(new Error());