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,28 +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 url contains navTool url parameter. Overwrite settings with parameter.
25
- const url = new URL ( window . location . href ) ;
26
- const urlParams = new URLSearchParams ( url . search ) ;
27
- if ( urlParams . get ( 'navTool' ) ) {
28
- type = urlParams . get ( 'navTool' ) ;
29
- }
30
-
31
- // if there's a stored nav type in session storage, retrieve it and overwrite type
32
- const sessionNavType = sessionStorage . getItem ( 'uni-nav[navType]' ) ;
33
- if ( sessionNavType && ( sessionNavType === 'tool' || sessionNavType === 'marketing' ) ) {
34
- type = sessionNavType ;
35
- }
36
-
37
- // store nav type for current session
38
- sessionStorage . setItem ( 'uni-nav[navType]' , type ) ;
39
- return type ;
40
- } , [ ] ) ;
41
18
42
19
const navigationUserInfo = {
43
20
...user ,
@@ -50,13 +27,21 @@ const TopcoderHeader = ({ auth }) => {
50
27
}
51
28
52
29
uniNavInitialized . current = true ;
53
- counter += 1 ;
54
30
55
31
const regSource = window . location . pathname . split ( '/' ) [ 1 ] ;
56
32
const retUrl = encodeURIComponent ( window . location . href ) ;
57
33
58
- tcUniNav ( 'init' , headerElId . current , {
59
- 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,
60
45
toolName : getSubPageConfiguration ( ) . toolName ,
61
46
toolRoot : getSubPageConfiguration ( ) . toolRoot ,
62
47
signOut : ( ) => {
@@ -69,15 +54,15 @@ const TopcoderHeader = ({ auth }) => {
69
54
window . location = `${ authURLs . location . replace ( '%S' , retUrl ) . replace ( 'member?' , '#!/member?' ) } &mode=signUp®Source=${ regSource } ` ;
70
55
} ,
71
56
} ) ;
72
- } , [ navType ] ) ;
57
+ } , [ ] ) ;
73
58
74
59
useEffect ( ( ) => {
75
- tcUniNav ( 'update' , headerElId . current , {
60
+ tcUniNav ( 'update' , headerElId , {
76
61
user : isAuthenticated ? navigationUserInfo : null ,
77
62
} ) ;
78
63
} , [ isAuthenticated , navigationUserInfo ] ) ;
79
64
80
- return < div id = { headerElId . current } ref = { headerRef } /> ;
65
+ return < div id = { headerElId } ref = { headerRef } /> ;
81
66
} ;
82
67
83
68
TopcoderHeader . defaultProps = {
0 commit comments