From 05c69481b513ed355f1fb18ae6561574e3527362 Mon Sep 17 00:00:00 2001 From: louiscklaw Date: Wed, 14 May 2025 18:10:22 +0800 Subject: [PATCH] update check session working, --- .../src/pages/auth/Home/index copy.tsx | 107 ++++++++++++++++++ .../src/pages/auth/Home/index.tsx | 22 +--- 2 files changed, 109 insertions(+), 20 deletions(-) create mode 100644 002_source/ionic_mobile/src/pages/auth/Home/index copy.tsx diff --git a/002_source/ionic_mobile/src/pages/auth/Home/index copy.tsx b/002_source/ionic_mobile/src/pages/auth/Home/index copy.tsx new file mode 100644 index 0000000..2b9e57d --- /dev/null +++ b/002_source/ionic_mobile/src/pages/auth/Home/index copy.tsx @@ -0,0 +1,107 @@ +import { + IonButton, + IonCardTitle, + IonCol, + IonContent, + IonFooter, + IonGrid, + IonHeader, + IonImg, + IonPage, + IonRouterLink, + IonRow, + IonToolbar, + useIonRouter, +} from '@ionic/react'; +// import { Action } from '../components/Action'; +import styles from './style.module.scss'; +import { Action } from '../../../components/Action'; +import { Paths } from '../../../Paths'; +import { useTranslation } from 'react-i18next'; +import { useEffect, useState } from 'react'; +import { useUser } from '../../../hooks/use-user'; +import { LoadingScreen } from '../../../components/LoadingScreen'; + +const AuthHome = () => { + const { t } = useTranslation(); + const { user, checkSession, isLoading } = useUser(); + const router = useIonRouter(); + + const [showLoading, setShowLoading] = useState(true); + const [showError, setShowErrr] = useState<{ show: boolean; message: string }>({ + show: false, + message: '', + }); + + const [checkingSession, setCheckingSession] = useState(true); + + useEffect(() => { + if (!checkingSession) { + if (!user) { + router.push(Paths.AuthLogin); + } else { + router.push(Paths.AuthorizedTest); + } + setShowLoading(false); + } + }, [user, checkingSession]); + + useEffect(() => { + checkSession?.() + .then(() => { + setCheckingSession(false); + }) + .catch((err) => console.error(err)); + }, [checkSession]); + + if (showLoading) return ; + // if (showError) return <>{showError.message}; + + return ( + + + {/* */} + + {/* */} + + +
+ + + + + {/* */} + Join millions of other people discovering their creative side + + + + + + + + + {/* */} + Get started → + + + + + +
+
+ + + + + + +
+ ); +}; + +export default AuthHome; diff --git a/002_source/ionic_mobile/src/pages/auth/Home/index.tsx b/002_source/ionic_mobile/src/pages/auth/Home/index.tsx index 7c8c729..3ee1795 100644 --- a/002_source/ionic_mobile/src/pages/auth/Home/index.tsx +++ b/002_source/ionic_mobile/src/pages/auth/Home/index.tsx @@ -24,37 +24,19 @@ import { LoadingScreen } from '../../../components/LoadingScreen'; const AuthHome = () => { const { t } = useTranslation(); - const { user, checkSession } = useUser(); - const router = useIonRouter(); const [showLoading, setShowLoading] = useState(true); const [showError, setShowErrr] = useState<{ show: boolean; message: string }>({ show: false, message: '', }); - const [checkingSession, setCheckingSession] = useState(true); useEffect(() => { - if (!checkingSession) { - if (!user) { - router.push(Paths.AuthLogin); - } else { - router.push(Paths.AuthorizedTest); - } - } setShowLoading(false); - }, [user, checkingSession]); - - useEffect(() => { - checkSession?.() - .then(() => { - setCheckingSession(false); - }) - .catch((err) => console.error(err)); - }, [checkSession]); + }, []); if (showLoading) return ; - // if (showError) return <>{showError.message}; + if (showError.show) return <>{showError.message}; return (