diff --git a/src/components/Api/Api.tsx b/src/components/Api/Api.tsx index 489ede2..b6362d7 100644 --- a/src/components/Api/Api.tsx +++ b/src/components/Api/Api.tsx @@ -2,6 +2,7 @@ import axios from "axios"; import AsyncStorage from "@react-native-async-storage/async-storage"; import { ActivationType, + LocationType, LoginType, OnboardingType, PatchUserInfoType, @@ -87,7 +88,6 @@ export async function GetConfig() { // User APIs export function UserRegister(register: RegistrationType) { - console.log(JSON.stringify(register)); return instance .post("/api/v1/accounts/users/", register) .then(async (response) => { @@ -148,7 +148,6 @@ export async function PatchUserInfo(info: PatchUserInfoType) { return instance .patch("/api/v1/accounts/users/me/", info, config) .then((response) => { - console.log(JSON.stringify(response.data)); return [true, response.data]; }) .catch((error) => { @@ -255,7 +254,6 @@ export async function PatchStudentStatus(info: StudentStatusPatchType) { }) .catch((error) => { let error_message = ParseError(error); - console.log("Error!", error.response.data); return [false, error_message]; }); } @@ -273,12 +271,11 @@ export async function GetStudentStatusList() { }); } -export async function GetStudentStatusListFiltered() { +export async function GetStudentStatusListNear() { const config = await GetConfig(); return instance - .get("/api/v1/student_status/filter/near_student_status", config) + .get("/api/v1/student_status/near/", config) .then((response) => { - console.log("test", response.data); return [true, response.data]; }) .catch((error) => { @@ -288,10 +285,18 @@ export async function GetStudentStatusListFiltered() { } // To-do -export async function GetStudentStatusListFilteredCurrentLocation() { +export async function GetStudentStatusListFilteredCurrentLocation( + location: LocationType +) { const config = await GetConfig(); return instance - .get("/api/v1/student_status/list/", config) + .post( + "/api/v1/student_status/near_current_location/", + { + location: location, + }, + config + ) .then((response) => { return [true, response.data]; }) @@ -329,7 +334,7 @@ export async function GetStudyGroupList() { export async function CreateStudyGroup(info: StudyGroupCreateType) { const config = await GetConfig(); - console.log("Payload:", info); + // console.log("Creating study group:", info); return instance .post("/api/v1/study_groups/create/", info, config) .then((response) => { diff --git a/src/components/DrawerSettings/CustomDrawerContent.tsx b/src/components/DrawerSettings/CustomDrawerContent.tsx index 738e656..b74d053 100644 --- a/src/components/DrawerSettings/CustomDrawerContent.tsx +++ b/src/components/DrawerSettings/CustomDrawerContent.tsx @@ -18,11 +18,13 @@ import { logout } from "../../features/redux/slices/StatusSlice/StatusSlice"; import AsyncStorage from "@react-native-async-storage/async-storage"; import UserIcon from "../../icons/UserIcon/UserIcon"; import SubjectIcon from "../../icons/SubjectIcon/SubjectIcon"; +import { useQueryClient } from "@tanstack/react-query"; export default function CustomDrawerContent(props: {}) { const navigation = useNavigation(); const status = useSelector((state: RootState) => state.status); const dispatch = useDispatch(); + const queryClient = useQueryClient(); if (status.logged_in && status.onboarding) { return ( @@ -40,6 +42,7 @@ export default function CustomDrawerContent(props: {}) { onPress={async () => { dispatch(logout()); await AsyncStorage.clear(); + queryClient.clear(); navigation.navigate("Login"); }} > diff --git a/src/routes/CreateGroup/CreateGroup.tsx b/src/routes/CreateGroup/CreateGroup.tsx index 9ada1af..0f4ec15 100644 --- a/src/routes/CreateGroup/CreateGroup.tsx +++ b/src/routes/CreateGroup/CreateGroup.tsx @@ -3,31 +3,20 @@ import styles, { Viewport } from "../../styles"; import { View, Text, - ToastAndroid, TextInput, NativeSyntheticEvent, TextInputChangeEventData, } from "react-native"; import { useState } from "react"; import { - UserInfoReturnType, - OptionType, RootDrawerParamList, - StudentStatusType, - StudentStatusReturnType, StudentStatusPatchType, StudyGroupCreateType, } from "../../interfaces/Interfaces"; import Button from "../../components/Button/Button"; -import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; -import { - PatchStudentStatus, - GetUserInfo, - ParseError, - CreateStudyGroup, -} from "../../components/Api/Api"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { PatchStudentStatus, CreateStudyGroup } from "../../components/Api/Api"; import { colors } from "../../styles"; -import DropDownPicker from "react-native-dropdown-picker"; import AnimatedContainerNoScroll from "../../components/AnimatedContainer/AnimatedContainerNoScroll"; import { urlProvider } from "../../components/Api/Api"; import MapView, { UrlTile, Marker } from "react-native-maps"; @@ -170,13 +159,6 @@ export default function CreateGroup({ route }: any) { - , - { - type: "normal", - placement: "top", - duration: 2000, - animationType: "slide-in", - style: { - backgroundColor: colors.secondary_2, - borderWidth: 1, - borderColor: colors.primary_1, - }, - } - ); - }} - /> - - - ); - })} - {study_groups_global.map( - (studygroup: StudyGroupType, index: number) => { - const randomColorWithOpacity = `rgba(${Math.floor( - Math.random() * 256 - )}, ${Math.floor(Math.random() * 256)}, ${Math.floor( - Math.random() * 256 - )}, 0.7)`; - - return ( - - { - toast.hideAll(); - toast.show( - - - Subject: {studygroup.subject} - - - Students Studying: {studygroup.students.length} - - - , - { - type: "normal", - placement: "top", - duration: 2000, - animationType: "slide-in", - style: { - backgroundColor: colors.secondary_2, - borderWidth: 1, - borderColor: colors.primary_1, - }, - } - ); - }} - /> - - - ); - } - )} - { - const newLocation = e.nativeEvent.coordinate; - const distance = GetDistance( - newLocation.latitude, - newLocation.longitude, - location.coords.latitude, - location.coords.longitude - ); - if (distance <= 0.1) { - // If the new location is within 100 meters of the actual location, update the location state - setLocation({ - ...location, - coords: { - ...location.coords, - latitude: newLocation.latitude, - longitude: newLocation.longitude, - }, - }); - } else { - // If the new location is more than 100 meters away from the actual location, reset the marker to the actual location - setLocation({ - ...location, - }); - } - }} - pinColor={colors.primary_1} - onPress={() => { - toast.hideAll(); - toast.show( - - - You are here - - - - {"x: " + - (student_status?.location?.longitude != undefined - ? student_status?.location?.longitude.toFixed(4) - : location.coords.longitude.toFixed(4))} - - - {"y: " + - (student_status?.location?.latitude != undefined - ? student_status?.location?.latitude.toFixed(4) - : location.coords.latitude.toFixed(4))} - - {student_status?.active && - !student_status?.study_group ? ( - <> - - {student_status?.active - ? "Studying " + student_status?.subject - : ""} - - + ) : ( + <> + )} + {student_status?.study_group == + studygroup.name ? ( + + ) : ( + <> + )} + , + { + type: "normal", + placement: "top", + duration: 2000, + animationType: "slide-in", + style: { + backgroundColor: colors.secondary_2, + borderWidth: 1, + borderColor: colors.primary_1, + }, } - }} - > - - Create Group - - - - ) : ( - <> - )} - {student_status?.study_group ? ( - <> - - {`Studying ${student_status?.subject}`} - - - {`In group ${student_status?.study_group}`} - - - ) : ( - <> - )} - , - { - type: "normal", - placement: "top", - duration: 2000, - animationType: "slide-in", - style: { - backgroundColor: colors.secondary_2, - borderWidth: 1, - borderColor: colors.primary_1, - }, + ); + }} + /> + + + ); + } + ) + ) : ( + <> + )} + {!studying ? ( + study_groups_global.map( + (studygroup: StudyGroupType, index: number) => { + const randomColorWithOpacity = `rgba(${Math.floor( + Math.random() * 256 + )}, ${Math.floor(Math.random() * 256)}, ${Math.floor( + Math.random() * 256 + )}, 0.7)`; + + return ( + + { + toast.hideAll(); + toast.show( + + + Subject: {studygroup.subject} + + + Name: {studygroup.name} + + + Students Studying:{" "} + {studygroup.students.length} + + {student_status?.study_group != + studygroup.name ? ( + + Get closer to join + + ) : ( + <> + )} + , + { + type: "normal", + placement: "top", + duration: 2000, + animationType: "slide-in", + style: { + backgroundColor: colors.secondary_2, + borderWidth: 1, + borderColor: colors.primary_1, + }, + } + ); + }} + /> + + + ); + } + ) + ) : ( + <> + )} + {!studying || !student_status?.study_group ? ( + { + const newLocation = e.nativeEvent.coordinate; + const distance = GetDistance( + newLocation.latitude, + newLocation.longitude, + location.coords.latitude, + location.coords.longitude + ); + if (distance <= 0.1) { + // If the new location is within 100 meters of the actual location, update the location state + setLocation({ + ...location, + coords: { + ...location.coords, + latitude: newLocation.latitude, + longitude: newLocation.longitude, + }, + }); + } else { + // If the new location is more than 100 meters away from the actual location, reset the marker to the actual location + setLocation({ + ...location, + }); } - ); - }} - > + }} + pinColor={colors.primary_1} + onPress={() => { + toast.hideAll(); + toast.show( + + + You are here + + {student_status?.active && + !student_status?.study_group ? ( + <> + + {student_status?.active + ? "Studying " + student_status?.subject + : ""} + + + + ) : ( + <> + )} + {student_status?.study_group ? ( + <> + + {`Studying: ${student_status?.subject}`} + + + {`In group: ${student_status?.study_group}`} + + + ) : ( + <> + )} + , + { + type: "normal", + placement: "top", + duration: 2000, + animationType: "slide-in", + style: { + backgroundColor: colors.secondary_2, + borderWidth: 1, + borderColor: colors.primary_1, + }, + } + ); + }} + > + ) : ( + <> + )}