diff --git a/compass/app/home/layout.tsx b/compass/app/home/layout.tsx index 236616e..ec67157 100644 --- a/compass/app/home/layout.tsx +++ b/compass/app/home/layout.tsx @@ -15,6 +15,8 @@ export default function RootLayout({ const [isSidebarOpen, setIsSidebarOpen] = useState(true); const [user, setUser] = useState(); const router = useRouter(); + const [loading, setLoading] = useState(true); + useEffect(() => { async function getUser() { @@ -35,6 +37,7 @@ export default function RootLayout({ ); setUser(await userData.json()); + setLoading(false); } getUser(); @@ -50,6 +53,7 @@ export default function RootLayout({ setIsSidebarOpen={setIsSidebarOpen} isSidebarOpen={isSidebarOpen} isAdmin={user.role === Role.ADMIN} + loading={loading} />
{ + return ( +
+
+
+
+
+ ); +}; + +export default LoadingIcon; \ No newline at end of file diff --git a/compass/components/Sidebar/Sidebar.tsx b/compass/components/Sidebar/Sidebar.tsx index d82ab69..232eda7 100644 --- a/compass/components/Sidebar/Sidebar.tsx +++ b/compass/components/Sidebar/Sidebar.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; import { HomeIcon, ChevronDoubleLeftIcon, @@ -9,7 +9,9 @@ import { LockClosedIcon, } from "@heroicons/react/24/solid"; import { SidebarItem } from "./SidebarItem"; +import styles from "./LoadingIcon.module.css" import { UserProfile } from "../resource/UserProfile"; +import LoadingIcon from "./LoadingIcon"; interface SidebarProps { setIsSidebarOpen: React.Dispatch>; @@ -17,6 +19,7 @@ interface SidebarProps { name: string; email: string; isAdmin: boolean; + loading: boolean; } const Sidebar: React.FC = ({ @@ -25,7 +28,9 @@ const Sidebar: React.FC = ({ name, email, isAdmin: admin, + loading, }) => { + const [isLoading, setIsLoading] = useState(false); return ( <> {/* Button to open the sidebar. */} @@ -62,11 +67,18 @@ const Sidebar: React.FC = ({
-
- {/* user + logout button */} -
- + {/* Loading indicator*/} + {isLoading && ( +
+ {/* Spinner */}
+ )} + +
+
+ +
+ {/* navigation menu */}

diff --git a/compass/components/resource/UserProfile.tsx b/compass/components/resource/UserProfile.tsx index ee88eae..3d9f544 100644 --- a/compass/components/resource/UserProfile.tsx +++ b/compass/components/resource/UserProfile.tsx @@ -1,49 +1,36 @@ import { useState } from "react"; import { signOut } from "@/app/auth/actions"; -import LoggingOut from "../auth/LoggingOut"; interface UserProfileProps { name: string; email: string; + setLoading: React.Dispatch>; } const handleClick = async ( event: React.MouseEvent, setLoading: React.Dispatch> ) => { - setLoading(true); // Set loading state to true - - // Call signOut and wait for the process to complete before redirecting + setLoading(true); // Set loading to true await signOut(); - - // Once signOut is complete, the redirect should happen, but let's delay it to allow the loading state to be visible for a short time - setTimeout(() => { - // The signOut already handles the redirect, so we don't need to redirect here again. - setLoading(false); // Reset the loading state after the timeout (just in case) - }, 1000); // You can adjust this delay as needed + setLoading(false); // Reset loading after sign-out completes }; -export const UserProfile = ({ name, email }: UserProfileProps) => { - const [loading, setLoading] = useState(false); - - if (loading) { - // Show the "Logging out" screen while the sign-out process is in progress - return ; - } - +export const UserProfile = ({ name, email, setLoading }: UserProfileProps) => { return (
- {name} + + {name} + {email}
); -}; \ No newline at end of file +};