@@ -3,11 +3,13 @@ import {
3
3
FC ,
4
4
MutableRefObject ,
5
5
SetStateAction ,
6
+ useCallback ,
6
7
useContext ,
7
8
useEffect ,
8
9
useRef ,
9
10
useState ,
10
11
} from 'react'
12
+ import { NavigateFunction , useNavigate } from 'react-router-dom'
11
13
import classNames from 'classnames'
12
14
13
15
import { EnvironmentConfig , PageSubheaderPortalId } from '../config'
@@ -35,6 +37,27 @@ const Header: FC = () => {
35
37
const [ ready , setReady ] : [ boolean , Dispatch < SetStateAction < boolean > > ] = useState < boolean > ( false )
36
38
const headerInit : MutableRefObject < boolean > = useRef ( false )
37
39
const navElementId : string = 'main-nav-el'
40
+ const navigate : NavigateFunction = useNavigate ( )
41
+
42
+ console . debug ( 'active route' , activeToolRoute )
43
+
44
+ const navigationHandler : ( label : string , path : string ) => void
45
+ = useCallback ( ( label : string , path : string ) => {
46
+
47
+ console . debug ( path )
48
+
49
+ try {
50
+ // strip the domain and navigate to the path
51
+ navigate ( new URL ( path ) . pathname )
52
+ } catch ( error ) {
53
+ // if we couldn't navigate to the path, just go to the route of the currently active tool
54
+ navigate ( new URL ( activeToolRoute || '/' ) . pathname )
55
+ }
56
+
57
+ } , [
58
+ activeToolRoute ,
59
+ navigate ,
60
+ ] )
38
61
39
62
useEffect ( ( ) => {
40
63
@@ -48,17 +71,24 @@ const Header: FC = () => {
48
71
'init' ,
49
72
navElementId ,
50
73
{
74
+ navigationHandler,
51
75
onReady ( ) {
52
76
setReady ( true )
53
77
document . getElementById ( 'root' ) ?. classList . add ( 'app-ready' )
54
78
} ,
55
79
signIn ( ) { window . location . href = authUrlLogin ( ) } ,
56
80
signOut ( ) { window . location . href = authUrlLogout } ,
57
81
signUp ( ) { window . location . href = authUrlSignup ( ) } ,
82
+ toolName : activeToolName ,
83
+ toolRoute : activeToolRoute ,
58
84
type : 'tool' ,
59
85
} ,
60
86
)
61
- } , [ ] )
87
+ } , [
88
+ activeToolName ,
89
+ activeToolRoute ,
90
+ navigationHandler ,
91
+ ] )
62
92
63
93
useEffect ( ( ) => {
64
94
0 commit comments