Added loading pages inidcators to subject and user info page and redirect login page to homepage if user is already logged in

This commit is contained in:
Keannu Bernasol 2023-10-11 19:48:19 +08:00
parent 6e63f86805
commit 369a00a0b3
3 changed files with 38 additions and 5 deletions

View file

@ -7,8 +7,8 @@ import {
NativeSyntheticEvent, NativeSyntheticEvent,
TextInputChangeEventData, TextInputChangeEventData,
} from "react-native"; } from "react-native";
import { useDispatch } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { useState } from "react"; import { useEffect, useState } from "react";
import LoginIcon from "../../icons/LoginIcon/LoginIcon"; import LoginIcon from "../../icons/LoginIcon/LoginIcon";
import Button from "../../components/Button/Button"; import Button from "../../components/Button/Button";
import { useNavigation } from "@react-navigation/native"; import { useNavigation } from "@react-navigation/native";
@ -22,15 +22,22 @@ import {
unsetOnboarding, unsetOnboarding,
} from "../../features/redux/slices/StatusSlice/StatusSlice"; } from "../../features/redux/slices/StatusSlice/StatusSlice";
import { useToast } from "react-native-toast-notifications"; import { useToast } from "react-native-toast-notifications";
import { RootState } from "../../features/redux/Store/Store";
export default function Login() { export default function Login() {
const navigation = useNavigation<RootDrawerParamList>(); const navigation = useNavigation<RootDrawerParamList>();
const status = useSelector((state: RootState) => state.status);
const dispatch = useDispatch(); const dispatch = useDispatch();
const [creds, setCreds] = useState({ const [creds, setCreds] = useState({
username: "", username: "",
password: "", password: "",
}); });
const toast = useToast(); const toast = useToast();
useEffect(() => {
if (status.logged_in) {
navigation.navigate("Home");
}
}, []);
return ( return (
<View style={styles.background}> <View style={styles.background}>
<AnimatedContainer> <AnimatedContainer>

View file

@ -1,6 +1,6 @@
import * as React from "react"; import * as React from "react";
import styles from "../../styles"; import styles from "../../styles";
import { View, Text } from "react-native"; import { View, Text, ActivityIndicator } from "react-native";
import { useState } from "react"; import { useState } from "react";
import { import {
UserInfoReturnType, UserInfoReturnType,
@ -183,7 +183,17 @@ export default function SubjectsPage() {
); );
} }
} }
if (StudentInfo.isLoading || Subjects.isLoading) {
return (
<View style={styles.background}>
<AnimatedContainerNoScroll>
<View style={{ paddingVertical: 8 }} />
<ActivityIndicator size={96} color={colors.secondary_1} />
<Text style={styles.text_white_medium}>Loading...</Text>
</AnimatedContainerNoScroll>
</View>
);
}
return ( return (
<View style={styles.background}> <View style={styles.background}>
<AnimatedContainerNoScroll> <AnimatedContainerNoScroll>

View file

@ -7,6 +7,7 @@ import {
NativeSyntheticEvent, NativeSyntheticEvent,
TextInputChangeEventData, TextInputChangeEventData,
Pressable, Pressable,
ActivityIndicator,
} from "react-native"; } from "react-native";
import { useState } from "react"; import { useState } from "react";
import { import {
@ -285,7 +286,22 @@ export default function UserInfoPage() {
); );
} }
} }
if (
StudentInfo.isLoading ||
Semesters.isLoading ||
yearlevel_query.isLoading ||
course_query.isLoading
) {
return (
<View style={styles.background}>
<AnimatedContainerNoScroll>
<View style={{ paddingVertical: 8 }} />
<ActivityIndicator size={96} color={colors.secondary_1} />
<Text style={styles.text_white_medium}>Loading...</Text>
</AnimatedContainerNoScroll>
</View>
);
}
return ( return (
<View style={styles.background}> <View style={styles.background}>
<AnimatedContainerNoScroll> <AnimatedContainerNoScroll>