Do not redirect to conversations page if leaving a group

This commit is contained in:
Keannu Bernasol 2023-10-27 23:13:41 +08:00
parent 856621fe06
commit 5d7327ef26
2 changed files with 23 additions and 24 deletions

View file

@ -27,7 +27,7 @@ import { useToast } from "react-native-toast-notifications";
import MessageIcon from "../../icons/MessageIcon/MessageIcon"; import MessageIcon from "../../icons/MessageIcon/MessageIcon";
export default function CustomDrawerContent(props: {}) { export default function CustomDrawerContent(props: {}) {
const debug = false; const debug = true;
const navigation = useNavigation<RootDrawerParamList>(); const navigation = useNavigation<RootDrawerParamList>();
const status = useSelector((state: RootState) => state.status); const status = useSelector((state: RootState) => state.status);
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -143,7 +143,7 @@ export default function CustomDrawerContent(props: {}) {
<DrawerButton <DrawerButton
onPress={async () => { onPress={async () => {
// We don't clear student statuses when logging out on debug // We don't clear student statuses when logging out on debug
if (!debug) { if (debug) {
queryClient.clear(); queryClient.clear();
dispatch(logout()); dispatch(logout());
await AsyncStorage.clear(); await AsyncStorage.clear();

View file

@ -61,7 +61,7 @@ export default function Home() {
const [modalOpen, setModalOpen] = useState(false); const [modalOpen, setModalOpen] = useState(false);
const [modalByGroup, setModalByGroup] = useState(false); const [modalByGroup, setModalByGroup] = useState(false);
async function requestLocation() { async function requestLocationPermission() {
const { status } = await Location.requestForegroundPermissionsAsync(); const { status } = await Location.requestForegroundPermissionsAsync();
if (status !== "granted") { if (status !== "granted") {
setFeedback("Allow location permissions to continue"); setFeedback("Allow location permissions to continue");
@ -75,12 +75,13 @@ export default function Home() {
} }
); );
return; return;
} else {
setLocationPermitted(true);
} }
if (status == "granted") { }
if (locationPermitted === false) {
setLocationPermitted(true);
}
async function requestLocation() {
if (locationPermitted) {
let newLocation = await Location.getCurrentPositionAsync(); let newLocation = await Location.getCurrentPositionAsync();
if (newLocation) { if (newLocation) {
// Only update location state if user's location has changed // Only update location state if user's location has changed
@ -96,22 +97,18 @@ export default function Home() {
} }
} }
// Refresh every 10 seconds
useEffect(() => { useEffect(() => {
console.log("changed");
console.log(locationPermitted);
requestLocation();
}, [locationPermitted]);
useEffect(() => {
requestLocationPermission();
// Refresh every 30 seconds
const interval = setInterval(() => { const interval = setInterval(() => {
requestLocation(); requestLocation();
}, 30000); }, 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); return () => clearInterval(interval);
}, []); }, []);
@ -219,7 +216,7 @@ export default function Home() {
return data; return data;
}, },
onSuccess: () => { onSuccess: () => {
if (student_status?.study_group) { if (student_status?.study_group == "") {
// Display separate toast if you stop studying while in a 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, { toast.show("You left study group \n" + student_status?.study_group, {
type: "success", type: "success",
@ -227,8 +224,8 @@ export default function Home() {
duration: 2000, duration: 2000,
animationType: "slide-in", animationType: "slide-in",
}); });
navigation.navigate("Conversation");
} }
queryClient.invalidateQueries({ queryKey: ["user_status"] }); queryClient.invalidateQueries({ queryKey: ["user_status"] });
// Delay refetching for study groups since backend still needs to delete groups without students after leaving a study group // Delay refetching for study groups since backend still needs to delete groups without students after leaving a study group
@ -383,9 +380,9 @@ export default function Home() {
(!StudentStatusQuery.isSuccess && (!StudentStatusQuery.isSuccess &&
studying && studying &&
!StudentStatusListQuery.isSuccess && !StudentStatusListQuery.isSuccess &&
!StudyGroupQuery.isSuccess && !StudyGroupQuery.isSuccess) ||
!StudentStatusQuery.isSuccess) || (!StudentStatusQuery.isSuccess &&
(!studying && !studying &&
!StudentStatusListGlobalQuery.isSuccess && !StudentStatusListGlobalQuery.isSuccess &&
!StudyGroupGlobalQuery.isSuccess) !StudyGroupGlobalQuery.isSuccess)
) { ) {
@ -600,6 +597,7 @@ export default function Home() {
study_group: studygroup.name, study_group: studygroup.name,
subject: studygroup.subject, subject: studygroup.subject,
}); });
navigation.navigate("Conversation");
}} }}
> >
<Text style={styles.text_white_tiny_bold}> <Text style={styles.text_white_tiny_bold}>
@ -1051,6 +1049,7 @@ export default function Home() {
study_group: studygroup.name, study_group: studygroup.name,
subject: studygroup.subject, subject: studygroup.subject,
}); });
navigation.navigate("Conversation");
setModalOpen(!modalOpen); setModalOpen(!modalOpen);
}} }}
> >