Fix indefinite loading spinner when navigating to same page

This commit is contained in:
pmoharana-cmd 2024-12-16 00:13:50 -05:00
parent fdbf4ffa40
commit 63fa7db352
3 changed files with 6 additions and 7 deletions

View File

@ -15,7 +15,6 @@ export default function RootLayout({
const [isSidebarOpen, setIsSidebarOpen] = useState(true);
const [user, setUser] = useState<User>();
const router = useRouter();
const [loading, setLoading] = useState(true);
useEffect(() => {
async function getUser() {
@ -36,7 +35,6 @@ export default function RootLayout({
);
setUser(await userData.json());
setLoading(false);
}
getUser();
@ -52,7 +50,6 @@ export default function RootLayout({
setIsSidebarOpen={setIsSidebarOpen}
isSidebarOpen={isSidebarOpen}
isAdmin={user.role === Role.ADMIN}
loading={loading}
/>
<div
className={`flex-1 transition duration-300 ease-in-out ${

View File

@ -9,7 +9,6 @@ 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";
@ -19,7 +18,6 @@ interface SidebarProps {
name: string;
email: string;
isAdmin: boolean;
loading: boolean;
}
const Sidebar: React.FC<SidebarProps> = ({
@ -28,7 +26,6 @@ const Sidebar: React.FC<SidebarProps> = ({
name,
email,
isAdmin: admin,
loading,
}) => {
const [isLoading, setIsLoading] = useState(false);
return (

View File

@ -1,4 +1,5 @@
import Link from "next/link";
import { usePathname } from "next/navigation";
interface SidebarItemProps {
icon: React.ReactElement;
@ -15,9 +16,13 @@ export const SidebarItem: React.FC<SidebarItemProps> = ({
redirect,
onClick,
}) => {
const pathname = usePathname();
return (
<Link
onClick={() => onClick(true)}
onClick={() =>
pathname.startsWith(redirect) ? onClick(false) : onClick(true)
}
href={redirect}
className={
active