mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2024-11-17 06:19:25 +08:00
Code cleanup for multiple pages and components
This commit is contained in:
parent
14e14b8bb6
commit
68778cea7a
5 changed files with 22 additions and 13 deletions
|
@ -1,26 +1,26 @@
|
||||||
import { Callout } from "react-native-maps";
|
import { Callout } from "react-native-maps";
|
||||||
import { RawLocationType } from "../../interfaces/Interfaces";
|
import { LocationType, RawLocationType } from "../../interfaces/Interfaces";
|
||||||
import styles from "../../styles";
|
import styles from "../../styles";
|
||||||
import { Text } from "react-native";
|
import { Text } from "react-native";
|
||||||
|
|
||||||
// Map popup for user's location
|
// Map popup for user's location
|
||||||
|
|
||||||
type props = {
|
type props = {
|
||||||
location: RawLocationType;
|
location: LocationType;
|
||||||
studying: boolean;
|
studying: boolean;
|
||||||
subject?: string;
|
subject?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function CustomMapCallout(props: props) {
|
export default function CustomMapCallout(props: props) {
|
||||||
let { location, studying, subject } = props;
|
let { location, studying, subject } = props;
|
||||||
if (location && location.coords) {
|
if (location && location.latitude && location.longitude) {
|
||||||
if (studying) {
|
if (studying) {
|
||||||
return (
|
return (
|
||||||
<Callout>
|
<Callout>
|
||||||
<Text style={styles.text_black_tiny}>
|
<Text style={styles.text_black_tiny}>
|
||||||
You are here {"\n"}
|
You are here {"\n"}
|
||||||
X: {Math.round(location.coords.longitude) + "\n"}
|
X: {Math.round(location.longitude) + "\n"}
|
||||||
Z: {Math.round(location.coords.latitude) + "\n"}
|
Z: {Math.round(location.latitude) + "\n"}
|
||||||
Studying: {subject}
|
Studying: {subject}
|
||||||
</Text>
|
</Text>
|
||||||
</Callout>
|
</Callout>
|
||||||
|
@ -30,8 +30,8 @@ export default function CustomMapCallout(props: props) {
|
||||||
<Callout>
|
<Callout>
|
||||||
<Text style={styles.text_black_tiny}>
|
<Text style={styles.text_black_tiny}>
|
||||||
You are here {"\n"}
|
You are here {"\n"}
|
||||||
X: {Math.round(location.coords.longitude) + "\n"}
|
X: {Math.round(location.longitude) + "\n"}
|
||||||
Z: {Math.round(location.coords.latitude)}
|
Z: {Math.round(location.latitude)}
|
||||||
</Text>
|
</Text>
|
||||||
</Callout>
|
</Callout>
|
||||||
);
|
);
|
||||||
|
|
|
@ -44,7 +44,7 @@ import GetDistanceFromUSTP from "../../components/GetDistance/GetDistanceFromUST
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
// Switch this condition to see the main map when debugging
|
// Switch this condition to see the main map when debugging
|
||||||
const map_debug = false;
|
const map_debug = true;
|
||||||
const navigation = useNavigation<RootDrawerParamList>();
|
const navigation = useNavigation<RootDrawerParamList>();
|
||||||
const [location, setLocation] = useState<RawLocationType | null>(null);
|
const [location, setLocation] = useState<RawLocationType | null>(null);
|
||||||
const [dist, setDist] = useState<number | null>(null);
|
const [dist, setDist] = useState<number | null>(null);
|
||||||
|
@ -119,6 +119,7 @@ export default function Home() {
|
||||||
const [studying, setStudying] = useState(false);
|
const [studying, setStudying] = useState(false);
|
||||||
const [subject, setSubject] = useState("");
|
const [subject, setSubject] = useState("");
|
||||||
const [buttonLabel, setButtonLabel] = useState("Start studying");
|
const [buttonLabel, setButtonLabel] = useState("Start studying");
|
||||||
|
const [student_status, setStudentStatus] = useState<StudentStatusType>();
|
||||||
const StudentStatus = useQuery({
|
const StudentStatus = useQuery({
|
||||||
queryKey: ["user_status"],
|
queryKey: ["user_status"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
@ -140,6 +141,8 @@ export default function Home() {
|
||||||
} else if (data[1].active == false) {
|
} else if (data[1].active == false) {
|
||||||
setButtonLabel("Start Studying");
|
setButtonLabel("Start Studying");
|
||||||
}
|
}
|
||||||
|
setStudentStatus(data[1]);
|
||||||
|
console.log(student_status);
|
||||||
},
|
},
|
||||||
onError: (error: Error) => {
|
onError: (error: Error) => {
|
||||||
toast.show(String(error), {
|
toast.show(String(error), {
|
||||||
|
@ -373,7 +376,7 @@ export default function Home() {
|
||||||
latitude: location.coords.latitude,
|
latitude: location.coords.latitude,
|
||||||
longitude: location.coords.longitude,
|
longitude: location.coords.longitude,
|
||||||
}}
|
}}
|
||||||
draggable
|
draggable={student_status?.active}
|
||||||
onDragEnd={(e) => {
|
onDragEnd={(e) => {
|
||||||
const newLocation = e.nativeEvent.coordinate;
|
const newLocation = e.nativeEvent.coordinate;
|
||||||
const distance = GetDistance(
|
const distance = GetDistance(
|
||||||
|
@ -402,7 +405,10 @@ export default function Home() {
|
||||||
pinColor={colors.primary_1}
|
pinColor={colors.primary_1}
|
||||||
>
|
>
|
||||||
<CustomMapCallout
|
<CustomMapCallout
|
||||||
location={location}
|
location={{
|
||||||
|
latitude: location.coords.latitude,
|
||||||
|
longitude: location.coords.longitude,
|
||||||
|
}}
|
||||||
studying={studying}
|
studying={studying}
|
||||||
subject={subject}
|
subject={subject}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
RootDrawerParamList,
|
RootDrawerParamList,
|
||||||
StudentStatusType,
|
StudentStatusType,
|
||||||
StudentStatusReturnType,
|
StudentStatusReturnType,
|
||||||
|
StudentStatusPatchType,
|
||||||
} from "../../interfaces/Interfaces";
|
} from "../../interfaces/Interfaces";
|
||||||
import Button from "../../components/Button/Button";
|
import Button from "../../components/Button/Button";
|
||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
@ -61,7 +62,7 @@ export default function StartStudying({ route }: any) {
|
||||||
});
|
});
|
||||||
|
|
||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
mutationFn: async (info: StudentStatusType) => {
|
mutationFn: async (info: StudentStatusPatchType) => {
|
||||||
const data = await PatchStudentStatus(info);
|
const data = await PatchStudentStatus(info);
|
||||||
if (data[0] == false) {
|
if (data[0] == false) {
|
||||||
return Promise.reject(new Error(JSON.stringify(data[1])));
|
return Promise.reject(new Error(JSON.stringify(data[1])));
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
OptionType,
|
OptionType,
|
||||||
StudentStatusType,
|
StudentStatusType,
|
||||||
PatchUserInfoType,
|
PatchUserInfoType,
|
||||||
|
StudentStatusPatchType,
|
||||||
} from "../../interfaces/Interfaces";
|
} from "../../interfaces/Interfaces";
|
||||||
import Button from "../../components/Button/Button";
|
import Button from "../../components/Button/Button";
|
||||||
import { Image } from "react-native";
|
import { Image } from "react-native";
|
||||||
|
@ -33,7 +34,7 @@ export default function SubjectsPage() {
|
||||||
|
|
||||||
// Student Status
|
// Student Status
|
||||||
const studentstatus_mutation = useMutation({
|
const studentstatus_mutation = useMutation({
|
||||||
mutationFn: async (info: StudentStatusType) => {
|
mutationFn: async (info: StudentStatusPatchType) => {
|
||||||
const data = await PatchStudentStatus(info);
|
const data = await PatchStudentStatus(info);
|
||||||
if (data[0] != true) {
|
if (data[0] != true) {
|
||||||
return Promise.reject(new Error());
|
return Promise.reject(new Error());
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {
|
||||||
OptionType,
|
OptionType,
|
||||||
StudentStatusType,
|
StudentStatusType,
|
||||||
PatchUserInfoType,
|
PatchUserInfoType,
|
||||||
|
StudentStatusPatchType,
|
||||||
} from "../../interfaces/Interfaces";
|
} from "../../interfaces/Interfaces";
|
||||||
import Button from "../../components/Button/Button";
|
import Button from "../../components/Button/Button";
|
||||||
import { Image } from "react-native";
|
import { Image } from "react-native";
|
||||||
|
@ -50,7 +51,7 @@ export default function UserInfoPage() {
|
||||||
|
|
||||||
// Student Status
|
// Student Status
|
||||||
const studentstatus_mutation = useMutation({
|
const studentstatus_mutation = useMutation({
|
||||||
mutationFn: async (info: StudentStatusType) => {
|
mutationFn: async (info: StudentStatusPatchType) => {
|
||||||
const data = await PatchStudentStatus(info);
|
const data = await PatchStudentStatus(info);
|
||||||
if (data[0] != true) {
|
if (data[0] != true) {
|
||||||
return Promise.reject(new Error());
|
return Promise.reject(new Error());
|
||||||
|
|
Loading…
Reference in a new issue