mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-20 10:30:16 -04:00
Fix indefinite loading spinner when navigating to same page
This commit is contained in:
parent
fdbf4ffa40
commit
63fa7db352
|
@ -15,7 +15,6 @@ export default function RootLayout({
|
||||||
const [isSidebarOpen, setIsSidebarOpen] = useState(true);
|
const [isSidebarOpen, setIsSidebarOpen] = useState(true);
|
||||||
const [user, setUser] = useState<User>();
|
const [user, setUser] = useState<User>();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getUser() {
|
async function getUser() {
|
||||||
|
@ -36,7 +35,6 @@ export default function RootLayout({
|
||||||
);
|
);
|
||||||
|
|
||||||
setUser(await userData.json());
|
setUser(await userData.json());
|
||||||
setLoading(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getUser();
|
getUser();
|
||||||
|
@ -52,7 +50,6 @@ export default function RootLayout({
|
||||||
setIsSidebarOpen={setIsSidebarOpen}
|
setIsSidebarOpen={setIsSidebarOpen}
|
||||||
isSidebarOpen={isSidebarOpen}
|
isSidebarOpen={isSidebarOpen}
|
||||||
isAdmin={user.role === Role.ADMIN}
|
isAdmin={user.role === Role.ADMIN}
|
||||||
loading={loading}
|
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
className={`flex-1 transition duration-300 ease-in-out ${
|
className={`flex-1 transition duration-300 ease-in-out ${
|
||||||
|
|
|
@ -9,7 +9,6 @@ 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 { UserProfile } from "../resource/UserProfile";
|
import { UserProfile } from "../resource/UserProfile";
|
||||||
import LoadingIcon from "./LoadingIcon";
|
import LoadingIcon from "./LoadingIcon";
|
||||||
|
|
||||||
|
@ -19,7 +18,6 @@ interface SidebarProps {
|
||||||
name: string;
|
name: string;
|
||||||
email: string;
|
email: string;
|
||||||
isAdmin: boolean;
|
isAdmin: boolean;
|
||||||
loading: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Sidebar: React.FC<SidebarProps> = ({
|
const Sidebar: React.FC<SidebarProps> = ({
|
||||||
|
@ -28,7 +26,6 @@ const Sidebar: React.FC<SidebarProps> = ({
|
||||||
name,
|
name,
|
||||||
email,
|
email,
|
||||||
isAdmin: admin,
|
isAdmin: admin,
|
||||||
loading,
|
|
||||||
}) => {
|
}) => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
|
|
||||||
interface SidebarItemProps {
|
interface SidebarItemProps {
|
||||||
icon: React.ReactElement;
|
icon: React.ReactElement;
|
||||||
|
@ -15,9 +16,13 @@ export const SidebarItem: React.FC<SidebarItemProps> = ({
|
||||||
redirect,
|
redirect,
|
||||||
onClick,
|
onClick,
|
||||||
}) => {
|
}) => {
|
||||||
|
const pathname = usePathname();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
onClick={() => onClick(true)}
|
onClick={() =>
|
||||||
|
pathname.startsWith(redirect) ? onClick(false) : onClick(true)
|
||||||
|
}
|
||||||
href={redirect}
|
href={redirect}
|
||||||
className={
|
className={
|
||||||
active
|
active
|
||||||
|
|
Loading…
Reference in New Issue
Block a user