mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2024-11-17 06:19:25 +08:00
Added study group creation
This commit is contained in:
parent
3c879b5cf2
commit
62cee96b94
3 changed files with 124 additions and 11 deletions
|
@ -8,6 +8,8 @@ import {
|
||||||
RegistrationType,
|
RegistrationType,
|
||||||
StudentStatusPatchType,
|
StudentStatusPatchType,
|
||||||
StudentStatusType,
|
StudentStatusType,
|
||||||
|
StudyGroupCreateType,
|
||||||
|
StudyGroupType,
|
||||||
} from "../../interfaces/Interfaces";
|
} from "../../interfaces/Interfaces";
|
||||||
|
|
||||||
export let backendURL = "https://stude.keannu1.duckdns.org";
|
export let backendURL = "https://stude.keannu1.duckdns.org";
|
||||||
|
@ -275,6 +277,7 @@ export async function GetStudentStatusListFiltered() {
|
||||||
return instance
|
return instance
|
||||||
.get("/api/v1/student_status/filter/near_student_status", config)
|
.get("/api/v1/student_status/filter/near_student_status", config)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
console.log("test", response.data);
|
||||||
return [true, response.data];
|
return [true, response.data];
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
@ -315,7 +318,20 @@ export async function GetStudyGroupList() {
|
||||||
return instance
|
return instance
|
||||||
.get("/api/v1/study_groups/", config)
|
.get("/api/v1/study_groups/", config)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log("test", response.data);
|
return [true, response.data];
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
let error_message = ParseError(error);
|
||||||
|
return [false, error_message];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function CreateStudyGroup(info: StudyGroupCreateType) {
|
||||||
|
const config = await GetConfig();
|
||||||
|
console.log("Payload:", info);
|
||||||
|
return instance
|
||||||
|
.post("/api/v1/study_groups/create/", info, config)
|
||||||
|
.then((response) => {
|
||||||
return [true, response.data];
|
return [true, response.data];
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|
|
@ -175,6 +175,13 @@ export interface StudyGroupType {
|
||||||
subject: string;
|
subject: string;
|
||||||
radius: number;
|
radius: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface StudyGroupCreateType {
|
||||||
|
name: string;
|
||||||
|
location: LocationType;
|
||||||
|
subject: string;
|
||||||
|
}
|
||||||
|
|
||||||
export type StudyGroupReturnType = [boolean, StudyGroupType[]];
|
export type StudyGroupReturnType = [boolean, StudyGroupType[]];
|
||||||
|
|
||||||
export type StudentStatusReturnType = [boolean, StudentStatusType];
|
export type StudentStatusReturnType = [boolean, StudentStatusType];
|
||||||
|
|
|
@ -27,9 +27,11 @@ import {
|
||||||
StudyGroupType,
|
StudyGroupType,
|
||||||
StudyGroupReturnType,
|
StudyGroupReturnType,
|
||||||
StudentStatusFilterType,
|
StudentStatusFilterType,
|
||||||
|
StudyGroupCreateType,
|
||||||
} from "../../interfaces/Interfaces";
|
} from "../../interfaces/Interfaces";
|
||||||
import { useNavigation } from "@react-navigation/native";
|
import { useNavigation } from "@react-navigation/native";
|
||||||
import {
|
import {
|
||||||
|
CreateStudyGroup,
|
||||||
GetStudentStatus,
|
GetStudentStatus,
|
||||||
GetStudentStatusList,
|
GetStudentStatusList,
|
||||||
GetStudentStatusListFiltered,
|
GetStudentStatusListFiltered,
|
||||||
|
@ -44,10 +46,13 @@ import React from "react";
|
||||||
import CustomMapCallout from "../../components/CustomMapCallout/CustomMapCallout";
|
import CustomMapCallout from "../../components/CustomMapCallout/CustomMapCallout";
|
||||||
import MapRendererFar from "../../components/MapRenderer/MapRendererFar";
|
import MapRendererFar from "../../components/MapRenderer/MapRendererFar";
|
||||||
import GetDistanceFromUSTP from "../../components/GetDistance/GetDistanceFromUSTP";
|
import GetDistanceFromUSTP from "../../components/GetDistance/GetDistanceFromUSTP";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import { RootState } from "../../features/redux/Store/Store";
|
||||||
|
|
||||||
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 = true;
|
const map_debug = true;
|
||||||
|
const user_state = useSelector((state: RootState) => state.user);
|
||||||
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);
|
||||||
|
@ -185,6 +190,34 @@ export default function Home() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const study_group_create = useMutation({
|
||||||
|
mutationFn: async (info: StudyGroupCreateType) => {
|
||||||
|
const data = await CreateStudyGroup(info);
|
||||||
|
if (data[0] != true) {
|
||||||
|
return Promise.reject(new Error());
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["user"] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["user_status"] });
|
||||||
|
toast.show("Created successfully", {
|
||||||
|
type: "success",
|
||||||
|
placement: "top",
|
||||||
|
duration: 2000,
|
||||||
|
animationType: "slide-in",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onError: (error: Error) => {
|
||||||
|
toast.show(String(error), {
|
||||||
|
type: "warning",
|
||||||
|
placement: "top",
|
||||||
|
duration: 2000,
|
||||||
|
animationType: "slide-in",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const [student_statuses, setStudentStatuses] =
|
const [student_statuses, setStudentStatuses] =
|
||||||
useState<StudentStatusListType>([]);
|
useState<StudentStatusListType>([]);
|
||||||
// Student Status List
|
// Student Status List
|
||||||
|
@ -531,16 +564,73 @@ export default function Home() {
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
pinColor={colors.primary_1}
|
pinColor={colors.primary_1}
|
||||||
>
|
onPress={() => {
|
||||||
<CustomMapCallout
|
toast.hideAll();
|
||||||
location={{
|
toast.show(
|
||||||
latitude: location.coords.latitude,
|
<View
|
||||||
longitude: location.coords.longitude,
|
style={{
|
||||||
}}
|
alignContent: "center",
|
||||||
studying={studying}
|
alignSelf: "center",
|
||||||
subject={subject}
|
justifyContent: "center",
|
||||||
/>
|
}}
|
||||||
</Marker>
|
>
|
||||||
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
|
You are here
|
||||||
|
</Text>
|
||||||
|
|
||||||
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
|
{"x: " +
|
||||||
|
(student_status?.location?.longitude != 0
|
||||||
|
? student_status?.location?.longitude.toFixed(4)
|
||||||
|
: location.coords.longitude.toFixed(4))}
|
||||||
|
</Text>
|
||||||
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
|
{"y: " +
|
||||||
|
(student_status?.location?.latitude != 0
|
||||||
|
? student_status?.location?.latitude.toFixed(4)
|
||||||
|
: location.coords.latitude.toFixed(4))}
|
||||||
|
</Text>
|
||||||
|
{studying ? (
|
||||||
|
<>
|
||||||
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
|
{studying
|
||||||
|
? "Studying " + student_status?.subject
|
||||||
|
: ""}
|
||||||
|
</Text>
|
||||||
|
<Button
|
||||||
|
onPress={() => {
|
||||||
|
if (student_status?.subject) {
|
||||||
|
study_group_create.mutate({
|
||||||
|
name: "asdasdasdasd",
|
||||||
|
location: location.coords,
|
||||||
|
subject: student_status?.subject,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
|
Create Group
|
||||||
|
</Text>
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
|
</View>,
|
||||||
|
{
|
||||||
|
type: "normal",
|
||||||
|
placement: "top",
|
||||||
|
duration: 2000,
|
||||||
|
animationType: "slide-in",
|
||||||
|
style: {
|
||||||
|
backgroundColor: colors.secondary_2,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: colors.primary_1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
></Marker>
|
||||||
</MapView>
|
</MapView>
|
||||||
<Button
|
<Button
|
||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
|
|
Loading…
Reference in a new issue