1
1
/* global tcUniNav */
2
- import React , { useEffect , useMemo , useRef } from 'react' ;
2
+ import React , { useEffect , useRef } from 'react' ;
3
3
import PT from 'prop-types' ;
4
4
import { connect } from 'react-redux' ;
5
5
import { config } from 'topcoder-react-utils' ;
6
6
import _ from 'lodash' ;
7
7
import { getInitials , getSubPageConfiguration } from '../utils/url' ;
8
8
9
- let counter = 0 ;
10
- const headerElIdTmpl = 'uninav-headerNav' ;
9
+ const headerElId = 'uninav-headerNav' ;
11
10
12
11
const TopcoderHeader = ( { auth } ) => {
13
12
const uniNavInitialized = useRef ( false ) ;
@@ -16,32 +15,6 @@ const TopcoderHeader = ({ auth }) => {
16
15
const isAuthenticated = ! ! authToken ;
17
16
const authURLs = config . HEADER_AUTH_URLS ;
18
17
const headerRef = useRef ( ) ;
19
- const headerElId = useRef ( `${ headerElIdTmpl } -${ counter } ` ) ;
20
-
21
- const navType = useMemo ( ( ) => {
22
- let { type } = getSubPageConfiguration ( ) ;
23
-
24
- if ( typeof window === 'undefined' ) {
25
- return type ;
26
- }
27
-
28
- // If url contains navTool url parameter. Overwrite settings with parameter.
29
- const url = new URL ( window . location . href ) ;
30
- const urlParams = new URLSearchParams ( url . search ) ;
31
- if ( urlParams . get ( 'navTool' ) ) {
32
- type = urlParams . get ( 'navTool' ) ;
33
- }
34
-
35
- // if there's a stored nav type in session storage, retrieve it and overwrite type
36
- const sessionNavType = sessionStorage . getItem ( 'uni-nav[navType]' ) ;
37
- if ( sessionNavType && ( sessionNavType === 'tool' || sessionNavType === 'marketing' ) ) {
38
- type = sessionNavType ;
39
- }
40
-
41
- // store nav type for current session
42
- sessionStorage . setItem ( 'uni-nav[navType]' , type ) ;
43
- return type ;
44
- } , [ ] ) ;
45
18
46
19
const navigationUserInfo = {
47
20
...user ,
@@ -54,13 +27,21 @@ const TopcoderHeader = ({ auth }) => {
54
27
}
55
28
56
29
uniNavInitialized . current = true ;
57
- counter += 1 ;
58
30
59
31
const regSource = window . location . pathname . split ( '/' ) [ 1 ] ;
60
32
const retUrl = encodeURIComponent ( window . location . href ) ;
61
33
62
- tcUniNav ( 'init' , headerElId . current , {
63
- type : navType ,
34
+ let { type } = getSubPageConfiguration ( ) ;
35
+
36
+ // If url contains navTool url parameter. Overwrite settings with parameter.
37
+ const url = new URL ( window . location . href ) ;
38
+ const urlParams = new URLSearchParams ( url . search ) ;
39
+ if ( urlParams . get ( 'navTool' ) ) {
40
+ type = urlParams . get ( 'navTool' ) ;
41
+ }
42
+
43
+ tcUniNav ( 'init' , headerElId , {
44
+ type,
64
45
toolName : getSubPageConfiguration ( ) . toolName ,
65
46
toolRoot : getSubPageConfiguration ( ) . toolRoot ,
66
47
signOut : ( ) => {
@@ -73,15 +54,15 @@ const TopcoderHeader = ({ auth }) => {
73
54
window . location = `${ authURLs . location . replace ( '%S' , retUrl ) . replace ( 'member?' , '#!/member?' ) } &mode=signUp®Source=${ regSource } ` ;
74
55
} ,
75
56
} ) ;
76
- } , [ navType ] ) ;
57
+ } , [ ] ) ;
77
58
78
59
useEffect ( ( ) => {
79
- tcUniNav ( 'update' , headerElId . current , {
60
+ tcUniNav ( 'update' , headerElId , {
80
61
user : isAuthenticated ? navigationUserInfo : null ,
81
62
} ) ;
82
63
} , [ isAuthenticated , navigationUserInfo ] ) ;
83
64
84
- return < div id = { headerElId . current } ref = { headerRef } /> ;
65
+ return < div id = { headerElId } ref = { headerRef } /> ;
85
66
} ;
86
67
87
68
TopcoderHeader . defaultProps = {
0 commit comments