From 146d80cc989b904407b0a36645aa17259a663270 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Tue, 15 Aug 2023 14:15:33 +0800 Subject: [PATCH] Added student status list query --- src/components/Api/Api.tsx | 13 +++++++++++++ src/interfaces/Interfaces.tsx | 4 ++++ src/routes/Home/Home.tsx | 34 +++++++++++++++++++++++++++++----- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/components/Api/Api.tsx b/src/components/Api/Api.tsx index bd53dd2..448f6fa 100644 --- a/src/components/Api/Api.tsx +++ b/src/components/Api/Api.tsx @@ -256,3 +256,16 @@ export async function PatchStudentStatus(info: StudentStatusType) { return [false, error_message]; }); } + +export async function GetStudentStatusList() { + const config = await GetConfig(); + return instance + .get("/api/v1/student_status/list/", config) + .then((response) => { + return [true, response.data]; + }) + .catch((error) => { + let error_message = ParseError(error); + return [false, error_message]; + }); +} diff --git a/src/interfaces/Interfaces.tsx b/src/interfaces/Interfaces.tsx index 85ef9ba..ffd85d9 100644 --- a/src/interfaces/Interfaces.tsx +++ b/src/interfaces/Interfaces.tsx @@ -1,4 +1,5 @@ import * as Location from "expo-location"; +import { GetStudentStatus } from "../components/Api/Api"; export interface IconProps { size: number; @@ -137,6 +138,9 @@ export interface StudentStatusType { export type StudentStatusReturnType = [boolean, StudentStatusType]; +export type StudentStatusListType = Array; +export type StudentStatusListReturnType = [boolean, StudentStatusListType]; + export type LocationType = Location.LocationObject; export interface UserInfoType { diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index 5230ffa..8328f3a 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -11,10 +11,12 @@ import { StudentStatusReturnType, LocationType, StudentStatusType, + StudentStatusListReturnType, } from "../../interfaces/Interfaces"; import { useNavigation } from "@react-navigation/native"; import { GetStudentStatus, + GetStudentStatusList, PatchStudentStatus, urlProvider, } from "../../components/Api/Api"; @@ -124,7 +126,6 @@ export default function Home() { } else if (data[1].active == false) { setButtonLabel("Start Studying"); } - console.log(data[1]); }, onError: (error: Error) => { toast.show(String(error), { @@ -163,6 +164,31 @@ export default function Home() { }); }, }); + + // Student Status List + const StudentStatusList = useQuery({ + queryKey: ["user_status_list"], + queryFn: async () => { + const data = await GetStudentStatusList(); + if (data[0] == false) { + return Promise.reject(new Error(JSON.stringify(data[1]))); + } + return data; + }, + onSuccess: (data: StudentStatusListReturnType) => { + console.log("List of students:", data[1]); + }, + onError: (error: Error) => { + toast.show(String(error), { + type: "warning", + placement: "top", + duration: 2000, + animationType: "slide-in", + }); + }, + }); + + // Map popup for user's location function CustomCallout() { if (location && location.coords) { if (studying) { @@ -235,7 +261,6 @@ export default function Home() { latitude: location.coords.latitude, longitude: location.coords.longitude, }} - onPress={() => console.log(location)} draggable onDragEnd={(e) => { const newLocation = e.nativeEvent.coordinate; @@ -245,7 +270,6 @@ export default function Home() { location.coords.latitude, location.coords.longitude ); - console.log("Distance:", distance); if (distance <= 0.1) { // If the new location is within 100 meters of the actual location, update the location state setLocation({ @@ -332,7 +356,6 @@ export default function Home() { latitude: location.coords.latitude, longitude: location.coords.longitude, }} - onPress={() => console.log(location)} pinColor={colors.primary_1} > @@ -351,10 +374,11 @@ export default function Home() { ); } } else { + requestLocation(); return ( {feedback} -