From 369a00a0b35a2b7b0a9a9ad5034177a5ed3edf63 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Wed, 11 Oct 2023 19:48:19 +0800 Subject: [PATCH] Added loading pages inidcators to subject and user info page and redirect login page to homepage if user is already logged in --- src/routes/Login/Login.tsx | 11 +++++++++-- src/routes/SubjectsPage/SubjectsPage.tsx | 14 ++++++++++++-- src/routes/UserInfoPage/UserInfoPage.tsx | 18 +++++++++++++++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/routes/Login/Login.tsx b/src/routes/Login/Login.tsx index 5a72b1a..b33ef2c 100644 --- a/src/routes/Login/Login.tsx +++ b/src/routes/Login/Login.tsx @@ -7,8 +7,8 @@ import { NativeSyntheticEvent, TextInputChangeEventData, } from "react-native"; -import { useDispatch } from "react-redux"; -import { useState } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import { useEffect, useState } from "react"; import LoginIcon from "../../icons/LoginIcon/LoginIcon"; import Button from "../../components/Button/Button"; import { useNavigation } from "@react-navigation/native"; @@ -22,15 +22,22 @@ import { unsetOnboarding, } from "../../features/redux/slices/StatusSlice/StatusSlice"; import { useToast } from "react-native-toast-notifications"; +import { RootState } from "../../features/redux/Store/Store"; export default function Login() { const navigation = useNavigation(); + const status = useSelector((state: RootState) => state.status); const dispatch = useDispatch(); const [creds, setCreds] = useState({ username: "", password: "", }); const toast = useToast(); + useEffect(() => { + if (status.logged_in) { + navigation.navigate("Home"); + } + }, []); return ( diff --git a/src/routes/SubjectsPage/SubjectsPage.tsx b/src/routes/SubjectsPage/SubjectsPage.tsx index cfee8f7..e7d5905 100644 --- a/src/routes/SubjectsPage/SubjectsPage.tsx +++ b/src/routes/SubjectsPage/SubjectsPage.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import styles from "../../styles"; -import { View, Text } from "react-native"; +import { View, Text, ActivityIndicator } from "react-native"; import { useState } from "react"; import { UserInfoReturnType, @@ -183,7 +183,17 @@ export default function SubjectsPage() { ); } } - + if (StudentInfo.isLoading || Subjects.isLoading) { + return ( + + + + + Loading... + + + ); + } return ( diff --git a/src/routes/UserInfoPage/UserInfoPage.tsx b/src/routes/UserInfoPage/UserInfoPage.tsx index 5d8a49b..129bdd4 100644 --- a/src/routes/UserInfoPage/UserInfoPage.tsx +++ b/src/routes/UserInfoPage/UserInfoPage.tsx @@ -7,6 +7,7 @@ import { NativeSyntheticEvent, TextInputChangeEventData, Pressable, + ActivityIndicator, } from "react-native"; import { useState } from "react"; import { @@ -285,7 +286,22 @@ export default function UserInfoPage() { ); } } - + if ( + StudentInfo.isLoading || + Semesters.isLoading || + yearlevel_query.isLoading || + course_query.isLoading + ) { + return ( + + + + + Loading... + + + ); + } return (