mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2024-11-17 06:19:25 +08:00
Added student status list query
This commit is contained in:
parent
cfd82d3c42
commit
146d80cc98
3 changed files with 46 additions and 5 deletions
|
@ -256,3 +256,16 @@ export async function PatchStudentStatus(info: StudentStatusType) {
|
||||||
return [false, error_message];
|
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];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import * as Location from "expo-location";
|
import * as Location from "expo-location";
|
||||||
|
import { GetStudentStatus } from "../components/Api/Api";
|
||||||
|
|
||||||
export interface IconProps {
|
export interface IconProps {
|
||||||
size: number;
|
size: number;
|
||||||
|
@ -137,6 +138,9 @@ export interface StudentStatusType {
|
||||||
|
|
||||||
export type StudentStatusReturnType = [boolean, StudentStatusType];
|
export type StudentStatusReturnType = [boolean, StudentStatusType];
|
||||||
|
|
||||||
|
export type StudentStatusListType = Array<StudentStatusType>;
|
||||||
|
export type StudentStatusListReturnType = [boolean, StudentStatusListType];
|
||||||
|
|
||||||
export type LocationType = Location.LocationObject;
|
export type LocationType = Location.LocationObject;
|
||||||
|
|
||||||
export interface UserInfoType {
|
export interface UserInfoType {
|
||||||
|
|
|
@ -11,10 +11,12 @@ import {
|
||||||
StudentStatusReturnType,
|
StudentStatusReturnType,
|
||||||
LocationType,
|
LocationType,
|
||||||
StudentStatusType,
|
StudentStatusType,
|
||||||
|
StudentStatusListReturnType,
|
||||||
} from "../../interfaces/Interfaces";
|
} from "../../interfaces/Interfaces";
|
||||||
import { useNavigation } from "@react-navigation/native";
|
import { useNavigation } from "@react-navigation/native";
|
||||||
import {
|
import {
|
||||||
GetStudentStatus,
|
GetStudentStatus,
|
||||||
|
GetStudentStatusList,
|
||||||
PatchStudentStatus,
|
PatchStudentStatus,
|
||||||
urlProvider,
|
urlProvider,
|
||||||
} from "../../components/Api/Api";
|
} from "../../components/Api/Api";
|
||||||
|
@ -124,7 +126,6 @@ export default function Home() {
|
||||||
} else if (data[1].active == false) {
|
} else if (data[1].active == false) {
|
||||||
setButtonLabel("Start Studying");
|
setButtonLabel("Start Studying");
|
||||||
}
|
}
|
||||||
console.log(data[1]);
|
|
||||||
},
|
},
|
||||||
onError: (error: Error) => {
|
onError: (error: Error) => {
|
||||||
toast.show(String(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() {
|
function CustomCallout() {
|
||||||
if (location && location.coords) {
|
if (location && location.coords) {
|
||||||
if (studying) {
|
if (studying) {
|
||||||
|
@ -235,7 +261,6 @@ export default function Home() {
|
||||||
latitude: location.coords.latitude,
|
latitude: location.coords.latitude,
|
||||||
longitude: location.coords.longitude,
|
longitude: location.coords.longitude,
|
||||||
}}
|
}}
|
||||||
onPress={() => console.log(location)}
|
|
||||||
draggable
|
draggable
|
||||||
onDragEnd={(e) => {
|
onDragEnd={(e) => {
|
||||||
const newLocation = e.nativeEvent.coordinate;
|
const newLocation = e.nativeEvent.coordinate;
|
||||||
|
@ -245,7 +270,6 @@ export default function Home() {
|
||||||
location.coords.latitude,
|
location.coords.latitude,
|
||||||
location.coords.longitude
|
location.coords.longitude
|
||||||
);
|
);
|
||||||
console.log("Distance:", distance);
|
|
||||||
if (distance <= 0.1) {
|
if (distance <= 0.1) {
|
||||||
// If the new location is within 100 meters of the actual location, update the location state
|
// If the new location is within 100 meters of the actual location, update the location state
|
||||||
setLocation({
|
setLocation({
|
||||||
|
@ -332,7 +356,6 @@ export default function Home() {
|
||||||
latitude: location.coords.latitude,
|
latitude: location.coords.latitude,
|
||||||
longitude: location.coords.longitude,
|
longitude: location.coords.longitude,
|
||||||
}}
|
}}
|
||||||
onPress={() => console.log(location)}
|
|
||||||
pinColor={colors.primary_1}
|
pinColor={colors.primary_1}
|
||||||
>
|
>
|
||||||
<Callout>
|
<Callout>
|
||||||
|
@ -351,10 +374,11 @@ export default function Home() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
requestLocation();
|
||||||
return (
|
return (
|
||||||
<AnimatedContainer>
|
<AnimatedContainer>
|
||||||
<Text style={styles.text_white_medium}>{feedback}</Text>
|
<Text style={styles.text_white_medium}>{feedback}</Text>
|
||||||
<Button onPress={() => requestLocation()}>
|
<Button onPress={requestLocation}>
|
||||||
<Text style={styles.text_white_medium}>Allow Access</Text>
|
<Text style={styles.text_white_medium}>Allow Access</Text>
|
||||||
</Button>
|
</Button>
|
||||||
</AnimatedContainer>
|
</AnimatedContainer>
|
||||||
|
|
Loading…
Reference in a new issue