diff --git a/beta/src/components/Layout/Sidebar/SidebarLink.tsx b/beta/src/components/Layout/Sidebar/SidebarLink.tsx index 72383a55..987a9428 100644 --- a/beta/src/components/Layout/Sidebar/SidebarLink.tsx +++ b/beta/src/components/Layout/Sidebar/SidebarLink.tsx @@ -21,6 +21,7 @@ interface SidebarLinkProps { isExpanded?: boolean; isBreadcrumb?: boolean; hideArrow?: boolean; + isPending: boolean; } export function SidebarLink({ @@ -32,6 +33,7 @@ export function SidebarLink({ isExpanded, isBreadcrumb, hideArrow, + isPending, }: SidebarLinkProps) { const ref = React.useRef(null); const isMobile = useIsMobile(); @@ -67,8 +69,11 @@ export function SidebarLink({ !selected && !heading, 'text-base text-link dark:text-link-dark bg-highlight dark:bg-highlight-dark border-blue-40 hover:bg-highlight hover:text-link dark:hover:bg-highlight-dark dark:hover:text-link-dark': selected, + 'dark:bg-gray-60 bg-gray-3 dark:hover:bg-gray-60 hover:bg-gray-3': + isPending, } )}> + {/* This here needs to be refactored ofc */} {title} {isExpanded != null && !heading && !hideArrow && ( { @@ -121,6 +123,7 @@ export function SidebarRouteTree({ { + const {events} = useRouter(); + const [pendingRoute, setPendingRoute] = React.useState(null); + const currentRoute = React.useRef(null); + React.useEffect(() => { + let routeTransitionTimer: any = null; + + const handleRouteChangeStart = (url: string) => { + clearTimeout(routeTransitionTimer); + routeTransitionTimer = setTimeout(() => { + if (currentRoute.current !== url) { + currentRoute.current = url; + setPendingRoute(url); + } + }, 100); + }; + const handleRouteChangeComplete = () => { + setPendingRoute(null); + clearTimeout(routeTransitionTimer); + }; + events.on('routeChangeStart', handleRouteChangeStart); + events.on('routeChangeComplete', handleRouteChangeComplete); + + return () => { + events.off('routeChangeStart', handleRouteChangeStart); + events.off('routeChangeComplete', handleRouteChangeComplete); + clearTimeout(routeTransitionTimer); + }; + }, []); + + return pendingRoute; +}; + +export default usePendingRoute;