Skip to content

Commit f24213e

Browse files
committed
Merge branch 'main' into dialogs
2 parents 7a4c168 + abe1764 commit f24213e

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/App.jsx

+12-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function App() {
2626
* This custom hook holds info about the current signed in user.
2727
* Check ./api/useAuth.jsx for its implementation.
2828
*/
29-
const { user } = useAuth();
29+
const { user, isLoadingUser } = useAuth();
3030
const userId = user?.uid;
3131
const userEmail = user?.email;
3232

@@ -45,7 +45,17 @@ export function App() {
4545
return (
4646
<Router>
4747
<Routes>
48-
<Route path="/" element={<Layout listPath={listPath} lists={lists} />}>
48+
<Route
49+
path="/"
50+
element={
51+
<Layout
52+
listPath={listPath}
53+
lists={lists}
54+
user={user}
55+
isLoadingUser={isLoadingUser}
56+
/>
57+
}
58+
>
4959
<Route
5060
index
5161
element={

src/api/useAuth.jsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,18 @@ export const SignOut = () => {
3434
*/
3535
export const useAuth = () => {
3636
const [user, setUser] = useState(null);
37+
const [isLoadingUser, setIsLoadingUser] = useState(false);
3738

3839
useEffect(() => {
40+
setIsLoadingUser(true);
3941
auth.onAuthStateChanged((user) => {
42+
setIsLoadingUser(false);
4043
setUser(user);
4144
if (user) {
4245
addUserToDatabase(user);
4346
}
4447
});
4548
}, []);
4649

47-
return { user };
50+
return { user, isLoadingUser };
4851
};

src/views/Layout.jsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { Outlet } from 'react-router-dom';
2-
import { SignIn, useAuth } from '../api/useAuth.jsx';
2+
import { SignIn } from '../api/useAuth.jsx';
33
import { NavBar } from '../components/NavBar/NavBar.jsx';
44
import Groceries from '../assets/groceries.png';
5+
import Loading from '../components/Loading.jsx';
56

6-
export function Layout({ lists, listPath }) {
7-
const { user } = useAuth();
8-
7+
export function Layout({ lists, listPath, user, isLoadingUser }) {
98
const handleClickSignIn = () => {
109
SignIn();
1110
};
@@ -14,7 +13,9 @@ export function Layout({ lists, listPath }) {
1413
<div className="w-screen flex flex-col text-poppins min-w-96 bg-puurWhite">
1514
<NavBar user={user} lists={lists} listPath={listPath} />
1615
<main className="min-h-screen w-full lg:pt-16 xl:w-9/12 xl:mx-auto">
17-
{!!user ? (
16+
{isLoadingUser ? (
17+
<Loading />
18+
) : !!user ? (
1819
<Outlet />
1920
) : (
2021
<div className="flex flex-col justify-items-center pt-12 lg:justify-between lg:m-20 lg:pt-0 lg:flex-row">

0 commit comments

Comments
 (0)