diff --git a/src/components/DrawerSettings/CustomDrawerContent.tsx b/src/components/DrawerSettings/CustomDrawerContent.tsx index 48c31e2..578d429 100644 --- a/src/components/DrawerSettings/CustomDrawerContent.tsx +++ b/src/components/DrawerSettings/CustomDrawerContent.tsx @@ -143,7 +143,7 @@ export default function CustomDrawerContent(props: {}) { { // We don't clear student statuses when logging out on debug - if (!debug) { + if (debug) { queryClient.clear(); dispatch(logout()); await AsyncStorage.clear(); diff --git a/src/icons/CaretLeftIcon/CaretLeftIcon.tsx b/src/icons/CaretLeftIcon/CaretLeftIcon.tsx index e2caaa5..eb5655e 100644 --- a/src/icons/CaretLeftIcon/CaretLeftIcon.tsx +++ b/src/icons/CaretLeftIcon/CaretLeftIcon.tsx @@ -3,7 +3,7 @@ import { IconProps } from "../../interfaces/Interfaces"; import { Svg, Path } from "react-native-svg"; import { colors } from "../../styles"; -export default function CaretLeftIcon(props: IconProps) { +export default function CaretRightIcon(props: IconProps) { return ( <> + + + + + + ); +} diff --git a/src/routes/ConversationPage/ConversationPage.tsx b/src/routes/ConversationPage/ConversationPage.tsx index b2fd297..6bec280 100644 --- a/src/routes/ConversationPage/ConversationPage.tsx +++ b/src/routes/ConversationPage/ConversationPage.tsx @@ -1,5 +1,5 @@ import * as React from "react"; -import { ActivityIndicator, Image } from "react-native"; +import { ActivityIndicator, Image, Pressable } from "react-native"; import styles from "../../styles"; import { View, @@ -36,6 +36,7 @@ import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContai import AsyncStorage from "@react-native-async-storage/async-storage"; import { useSelector } from "react-redux"; import { RootState } from "../../features/redux/Store/Store"; +import CaretRightIcon from "../../icons/CaretLeftIcon/CaretLeftIcon"; export default function ConversationPage() { const toast = useToast(); @@ -70,6 +71,7 @@ export default function ConversationPage() { enabled: student_status?.study_group != "" && student_status?.study_group != null, queryKey: ["study_group"], + refetchInterval: 10000, queryFn: async () => { const data = await GetStudyGroup(student_status?.study_group || ""); if (data[0] == false) { @@ -127,7 +129,7 @@ export default function ConversationPage() { // Avatar List const [users, setUsers] = useState([]); const AvatarsQuery = useQuery({ - refetchInterval: 3000, + refetchInterval: 10000, enabled: student_status?.study_group != null || (student_status?.study_group != "" && @@ -162,7 +164,7 @@ export default function ConversationPage() { mutationFn: async (info: MessagePostType) => { const data = await PostMessage(info); if (data[0] != true) { - return Promise.reject(new Error()); + return Promise.reject(new Error(data[1])); } return data; }, @@ -209,7 +211,9 @@ export default function ConversationPage() { paddingRight: 4, }} > - {studygroup.students.length} studying + {!StudyGroupQuery.isFetching + ? studygroup.students.length + " studying" + : "Loading"} {users.map((user: GroupMessageAvatarType, index: number) => { if (index > 6) { @@ -293,23 +297,41 @@ export default function ConversationPage() { There are no messages )} - - ): void => { - setMessage(e.nativeEvent.text); - }} - onSubmitEditing={() => { - send_message.mutate({ - message_content: message, - }); - setMessage(""); - }} - /> + + + ): void => { + setMessage(e.nativeEvent.text); + }} + onSubmitEditing={() => { + send_message.mutate({ + message_content: message, + }); + setMessage(""); + }} + /> + { + send_message.mutate({ + message_content: message, + }); + setMessage(""); + }} + > + + + ); diff --git a/src/routes/CreateGroup/CreateGroup.tsx b/src/routes/CreateGroup/CreateGroup.tsx index 904d472..26b30de 100644 --- a/src/routes/CreateGroup/CreateGroup.tsx +++ b/src/routes/CreateGroup/CreateGroup.tsx @@ -24,6 +24,7 @@ import MapView, { UrlTile, Marker } from "react-native-maps"; import { useNavigation } from "@react-navigation/native"; import { useToast } from "react-native-toast-notifications"; import CaretLeftIcon from "../../icons/CaretLeftIcon/CaretLeftIcon"; +import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer"; export default function CreateGroup({ route }: any) { const { location, subject } = route.params; @@ -82,9 +83,9 @@ export default function CreateGroup({ route }: any) { duration: 2000, animationType: "slide-in", }); - // Set a delay before going back to homepage to hopefully let the queries refresh in time + // Set a delay before going back to conversation page to hopefully let the queries refresh in time setTimeout(() => { - navigation.navigate("Home"); + navigation.navigate("Conversation"); }, 200); }, onError: (error: Error) => { @@ -100,7 +101,7 @@ export default function CreateGroup({ route }: any) { if (location) { return ( - + @@ -183,7 +184,7 @@ export default function CreateGroup({ route }: any) { - + ); } diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index 9ee173d..3769c06 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -44,6 +44,7 @@ import Modal from "react-native-modal"; import DropdownIcon from "../../icons/CaretDownIcon/CaretDownIcon"; import CaretUpIcon from "../../icons/CaretUpIcon/CaretUpIcon"; import RefreshIcon from "../../icons/RefreshIcon/RefreshIcon"; +import AsyncStorage from "@react-native-async-storage/async-storage"; export default function Home() { // Switch this condition to see the main map when debugging @@ -61,7 +62,7 @@ export default function Home() { const [modalOpen, setModalOpen] = useState(false); const [modalByGroup, setModalByGroup] = useState(false); - async function requestLocation() { + async function requestLocationPermission() { const { status } = await Location.requestForegroundPermissionsAsync(); if (status !== "granted") { setFeedback("Allow location permissions to continue"); @@ -75,12 +76,13 @@ export default function Home() { } ); return; + } else { + setLocationPermitted(true); } - if (status == "granted") { - if (locationPermitted === false) { - setLocationPermitted(true); - } + } + async function requestLocation() { + if (locationPermitted) { let newLocation = await Location.getCurrentPositionAsync(); if (newLocation) { // Only update location state if user's location has changed @@ -96,23 +98,18 @@ export default function Home() { } } - // Refresh every 10 seconds - requestLocation(); useEffect(() => { + console.log("changed"); + console.log(locationPermitted); + requestLocation(); + }, [locationPermitted]); + + useEffect(() => { + requestLocationPermission(); + // Refresh every 30 seconds const interval = setInterval(() => { requestLocation(); }, 30000); - setTimeout(() => { - queryClient.invalidateQueries({ queryKey: ["user"] }); - queryClient.invalidateQueries({ queryKey: ["user_status"] }); - queryClient.invalidateQueries({ - queryKey: ["user_status_list"], - }); - queryClient.invalidateQueries({ - queryKey: ["study_group_list"], - }); - requestLocation(); - }, 2000); return () => clearInterval(interval); }, []); @@ -129,6 +126,9 @@ export default function Home() { } } + async function clear_messages_notification_cache() { + AsyncStorage.setItem("messages", ""); + } // Student Status const [studying, setStudying] = useState(false); const [subject, setSubject] = useState(""); @@ -167,7 +167,7 @@ export default function Home() { mutationFn: async (info: StudentStatusPatchType) => { const data = await PatchStudentStatus(info); if (data[0] != true) { - return Promise.reject(new Error()); + return Promise.reject(new Error(JSON.stringify(data[1]))); } return data; }, @@ -220,7 +220,7 @@ export default function Home() { return data; }, onSuccess: () => { - if (student_status?.study_group) { + if (student_status?.study_group == "") { // Display separate toast if you stop studying while in a study group toast.show("You left study group \n" + student_status?.study_group, { type: "success", @@ -228,7 +228,9 @@ export default function Home() { duration: 2000, animationType: "slide-in", }); + clear_messages_notification_cache(); } + queryClient.invalidateQueries({ queryKey: ["user_status"] }); // Delay refetching for study groups since backend still needs to delete groups without students after leaving a study group @@ -380,12 +382,14 @@ export default function Home() { ); } else if ( - (StudentStatusQuery.isFetching && studying) || - StudentStatusListQuery.isFetching || - StudyGroupQuery.isFetching || - (StudentStatusQuery.isFetching && !studying) || - StudentStatusListGlobalQuery.isFetching || - StudyGroupGlobalQuery.isFetching + (!StudentStatusQuery.isSuccess && + studying && + !StudentStatusListQuery.isSuccess && + !StudyGroupQuery.isSuccess) || + (!StudentStatusQuery.isSuccess && + !studying && + !StudentStatusListGlobalQuery.isSuccess && + !StudyGroupGlobalQuery.isSuccess) ) { return ( <> @@ -598,6 +602,7 @@ export default function Home() { study_group: studygroup.name, subject: studygroup.subject, }); + navigation.navigate("Conversation"); }} > @@ -932,6 +937,8 @@ export default function Home() { return ; } } else { + requestLocationPermission(); + requestLocation(); return ( <> @@ -1049,6 +1056,7 @@ export default function Home() { study_group: studygroup.name, subject: studygroup.subject, }); + navigation.navigate("Conversation"); setModalOpen(!modalOpen); }} > diff --git a/src/routes/Register/Register.tsx b/src/routes/Register/Register.tsx index f9ac188..98a46ce 100644 --- a/src/routes/Register/Register.tsx +++ b/src/routes/Register/Register.tsx @@ -17,6 +17,7 @@ import { UserRegister } from "../../components/Api/Api"; import IsNumber from "../../components/IsNumber/IsNumber"; import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer"; import { useToast } from "react-native-toast-notifications"; +import { ScrollView } from "react-native-gesture-handler"; export default function Register() { const navigation = useNavigation(); diff --git a/src/styles.tsx b/src/styles.tsx index af0d3fa..71beda4 100644 --- a/src/styles.tsx +++ b/src/styles.tsx @@ -44,8 +44,9 @@ const styles = StyleSheet.create({ justifyContent: "center", display: "flex", flexDirection: "column", - flex: 1, + flexGrow: 1, paddingHorizontal: 4, + paddingVertical: 32, }, flex_row: { display: "flex",