mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-20 10:30:16 -04:00
Add loading functionality for changing pages
This commit is contained in:
parent
3ed505bcf3
commit
e7f54560e1
|
@ -24,8 +24,8 @@ This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-opti
|
||||||
|
|
||||||
To learn more about Next.js, take a look at the following resources:
|
To learn more about Next.js, take a look at the following resources:
|
||||||
|
|
||||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||||
|
|
||||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
|
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ export default function RootLayout({
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getUser() {
|
async function getUser() {
|
||||||
const supabase = createClient();
|
const supabase = createClient();
|
||||||
|
|
|
@ -33,7 +33,7 @@ export default function RootLayout({
|
||||||
);
|
);
|
||||||
|
|
||||||
const user: User = await userData.json();
|
const user: User = await userData.json();
|
||||||
setUser(user); // Set user data after fetching
|
setUser(user); // Set user data after fetching
|
||||||
}
|
}
|
||||||
|
|
||||||
getUser();
|
getUser();
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@keyframes spin {
|
@keyframes spin {
|
||||||
0% {
|
0% {
|
||||||
transform: rotate(0deg); /* Start position */
|
transform: rotate(0deg); /* Start position */
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
LockClosedIcon,
|
LockClosedIcon,
|
||||||
} from "@heroicons/react/24/solid";
|
} from "@heroicons/react/24/solid";
|
||||||
import { SidebarItem } from "./SidebarItem";
|
import { SidebarItem } from "./SidebarItem";
|
||||||
import styles from "./LoadingIcon.module.css"
|
import styles from "./LoadingIcon.module.css";
|
||||||
import { UserProfile } from "../resource/UserProfile";
|
import { UserProfile } from "../resource/UserProfile";
|
||||||
import LoadingIcon from "./LoadingIcon";
|
import LoadingIcon from "./LoadingIcon";
|
||||||
|
|
||||||
|
@ -67,16 +67,20 @@ const Sidebar: React.FC<SidebarProps> = ({
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Loading indicator*/}
|
{/* Loading indicator*/}
|
||||||
{isLoading && (
|
{isLoading && (
|
||||||
<div className="fixed top-2 left-2">
|
<div className="fixed top-2 left-2">
|
||||||
<LoadingIcon/>{/* Spinner */}
|
<LoadingIcon />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="flex flex-col space-y-8">
|
<div className="flex flex-col space-y-8">
|
||||||
<div className="flex items-center p-4 space-x-2 border rounded-md">
|
<div className="flex items-center p-4 space-x-2 border rounded-md">
|
||||||
<UserProfile name={name} email={email} setLoading={setIsLoading} />
|
<UserProfile
|
||||||
|
name={name}
|
||||||
|
email={email}
|
||||||
|
setLoading={setIsLoading}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* navigation menu */}
|
{/* navigation menu */}
|
||||||
|
@ -91,6 +95,7 @@ const Sidebar: React.FC<SidebarProps> = ({
|
||||||
text="Admin"
|
text="Admin"
|
||||||
active={true}
|
active={true}
|
||||||
redirect="/admin"
|
redirect="/admin"
|
||||||
|
onClick={setIsLoading}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
@ -99,24 +104,28 @@ const Sidebar: React.FC<SidebarProps> = ({
|
||||||
text="Home"
|
text="Home"
|
||||||
active={true}
|
active={true}
|
||||||
redirect="/home"
|
redirect="/home"
|
||||||
|
onClick={setIsLoading}
|
||||||
/>
|
/>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
icon={<BookmarkIcon />}
|
icon={<BookmarkIcon />}
|
||||||
text="Resources"
|
text="Resources"
|
||||||
active={true}
|
active={true}
|
||||||
redirect="/resource"
|
redirect="/resource"
|
||||||
|
onClick={setIsLoading}
|
||||||
/>
|
/>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
icon={<ClipboardIcon />}
|
icon={<ClipboardIcon />}
|
||||||
text="Services"
|
text="Services"
|
||||||
active={true}
|
active={true}
|
||||||
redirect="/service"
|
redirect="/service"
|
||||||
|
onClick={setIsLoading}
|
||||||
/>
|
/>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
icon={<BookOpenIcon />}
|
icon={<BookOpenIcon />}
|
||||||
text="Training Manuals"
|
text="Training Manuals"
|
||||||
active={true}
|
active={true}
|
||||||
redirect="/training-manuals"
|
redirect="/training-manuals"
|
||||||
|
onClick={setIsLoading}
|
||||||
/>
|
/>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -5,6 +5,7 @@ interface SidebarItemProps {
|
||||||
text: string;
|
text: string;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
redirect: string;
|
redirect: string;
|
||||||
|
onClick: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SidebarItem: React.FC<SidebarItemProps> = ({
|
export const SidebarItem: React.FC<SidebarItemProps> = ({
|
||||||
|
@ -12,9 +13,11 @@ export const SidebarItem: React.FC<SidebarItemProps> = ({
|
||||||
text,
|
text,
|
||||||
active,
|
active,
|
||||||
redirect,
|
redirect,
|
||||||
|
onClick,
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
|
onClick={() => onClick(true)}
|
||||||
href={redirect}
|
href={redirect}
|
||||||
className={
|
className={
|
||||||
active
|
active
|
||||||
|
|
|
@ -11,9 +11,8 @@ const handleClick = async (
|
||||||
event: React.MouseEvent<HTMLButtonElement>,
|
event: React.MouseEvent<HTMLButtonElement>,
|
||||||
setLoading: React.Dispatch<React.SetStateAction<boolean>>
|
setLoading: React.Dispatch<React.SetStateAction<boolean>>
|
||||||
) => {
|
) => {
|
||||||
setLoading(true); // Set loading to true
|
setLoading(true);
|
||||||
await signOut();
|
await signOut();
|
||||||
setLoading(false); // Reset loading after sign-out completes
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const UserProfile = ({ name, email, setLoading }: UserProfileProps) => {
|
export const UserProfile = ({ name, email, setLoading }: UserProfileProps) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user