@@ -11,7 +11,6 @@ import { useRouter } from 'next/router';
1111import Image from 'next/image' ;
1212import cn from 'classnames' ;
1313import dynamic from 'next/dynamic' ;
14- import { usePathname } from 'next/navigation' ;
1514
1615import type { TRouter } from '@local-types/global' ;
1716import { UserTypes } from '@local-types/uxcat-types/types' ;
@@ -93,15 +92,11 @@ const ToolHeader: FC<TToolHeader> = ({
9392 const router = useRouter ( ) ;
9493 const { locale, asPath } = router as TRouter ;
9594
96- const pathname = usePathname ( ) ?? '' ;
9795 const { isMobile } = useMobile ( ) [ 1 ] ;
9896 const [ , { isCoreView } ] = useUXCoreGlobals ( ) ;
9997 const { accountData, setAccountData, ourProjectsModalData } =
10098 useContext ( GlobalContext ) ;
10199
102- const isActive = ( pathname : string , href : string ) =>
103- pathname === href || ( href !== '/' && pathname ?. startsWith ( href + '/' ) ) ;
104-
105100 const imageSrc = useMemo ( ( ) => accountData ?. picture , [ accountData ] ) ;
106101 const [ showDropdown , setShowDropdown ] = useState ( false ) ;
107102 const [ openOurProjects , setOpenOurProjects ] = useState ( false ) ;
@@ -159,34 +154,37 @@ const ToolHeader: FC<TToolHeader> = ({
159154 const title = changedTitle ? userInfo ?. title : userInfo ?. user ?. title ;
160155
161156 useEffect ( ( ) => {
162- if ( ! router . isReady ) return ;
157+ const initial = getActiveFromPath ( router . asPath ) ;
158+ if ( initial ) setActivePage ( initial ) ;
163159
164- const onStart = ( ) => {
160+ const onStart = ( url : string ) => {
165161 isRoutingRef . current = true ;
162+
163+ const next = getActiveFromPath ( url ) ;
164+ if ( next ) setActivePage ( next ) ;
166165 } ;
167166
168- const onDone = ( url : string ) => {
167+ const onComplete = ( url : string ) => {
169168 isRoutingRef . current = false ;
170169
171170 const next = getActiveFromPath ( url ) ;
172171 if ( next ) setActivePage ( next ) ;
173172 } ;
174173
175- router . events . on ( 'routeChangeStart' , onStart ) ;
176- router . events . on ( 'routeChangeComplete' , onDone ) ;
177- router . events . on ( 'routeChangeError' , ( ) => {
174+ const onError = ( ) => {
178175 isRoutingRef . current = false ;
179- } ) ;
176+ } ;
180177
181- const initial = getActiveFromPath ( router . asPath ) ;
182- if ( initial ) setActivePage ( initial ) ;
178+ router . events . on ( 'routeChangeStart' , onStart ) ;
179+ router . events . on ( 'routeChangeComplete' , onComplete ) ;
180+ router . events . on ( 'routeChangeError' , onError ) ;
183181
184182 return ( ) => {
185183 router . events . off ( 'routeChangeStart' , onStart ) ;
186- router . events . off ( 'routeChangeComplete' , onDone ) ;
187- router . events . off ( 'routeChangeError' , onDone as any ) ;
184+ router . events . off ( 'routeChangeComplete' , onComplete ) ;
185+ router . events . off ( 'routeChangeError' , onError ) ;
188186 } ;
189- } , [ router . isReady , router . events , router . asPath ] ) ;
187+ } , [ router . events , router . asPath ] ) ;
190188
191189 const openPodcastHandler = useCallback ( ( ) => {
192190 setOpenPodcast ( prev => ! prev ) ;
@@ -326,8 +324,7 @@ const ToolHeader: FC<TToolHeader> = ({
326324 >
327325 < a
328326 className = { cn ( styles . MenuItem , {
329- [ styles . Active ] :
330- isActive ( pathname , href ) || activePage === page ,
327+ [ styles . Active ] : activePage === page ,
331328 [ styles [ `${ page } -MenuItem` ] ] : ! ! page ,
332329 } ) }
333330 target = {
0 commit comments