Skip to content

Commit 05e3757

Browse files
authored
Merge pull request #6795 from topcoder-platform/PROD-3777_universal_nav-load
PROD-3777 universal nav load
2 parents 0493e61 + 3a09055 commit 05e3757

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed
Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,35 @@
11
/* global tcUniNav */
2-
import React, { useEffect, useRef, useState } from 'react';
2+
import React, { useEffect, useRef } from 'react';
33
import { getSubPageConfiguration } from '../../utils/url';
44

5-
let uniqueId = 0;
5+
const footerElId = 'uninav-footerNav';
66

77
export default function TopcoderFooter() {
88
const footerRef = useRef();
99
const footerInitialized = useRef(false);
10-
const [footerId, setFooterId] = useState(0);
1110

1211
useEffect(() => {
13-
uniqueId += 1;
14-
setFooterId(uniqueId);
15-
}, []);
16-
17-
useEffect(() => {
18-
if (footerInitialized.current || !footerId) {
12+
if (footerInitialized.current) {
1913
return;
2014
}
2115

2216
footerInitialized.current = true;
2317

18+
let { fullFooter } = getSubPageConfiguration();
19+
2420
// If url contains navTool url parameter. Overwrite settings with parameter.
25-
let isFullFooter = false;
2621
const url = new URL(window.location.href);
2722
const urlParams = new URLSearchParams(url.search);
28-
if (urlParams.get('navTool') === 'tool') {
29-
isFullFooter = false;
30-
} else if (urlParams.get('navTool') === 'marketing') {
31-
isFullFooter = true;
32-
} else {
33-
isFullFooter = getSubPageConfiguration().fullFooter;
23+
const navToolParam = urlParams.get('navTool');
24+
if (navToolParam) {
25+
fullFooter = navToolParam !== 'tool';
3426
}
3527

36-
tcUniNav('init', `footerNav-${footerId}`, {
28+
tcUniNav('init', footerElId, {
29+
fullFooter,
3730
type: 'footer',
38-
fullFooter: isFullFooter,
3931
});
40-
}, [footerId]);
32+
}, []);
4133

42-
return <div id={`footerNav-${footerId}`} ref={footerRef} />;
34+
return <div id={footerElId} ref={footerRef} />;
4335
}

src/shared/containers/TopcoderHeader.jsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* global tcUniNav */
2-
import React, { useEffect, useRef, useState } from 'react';
2+
import React, { useEffect, useRef } from 'react';
33
import PT from 'prop-types';
44
import { connect } from 'react-redux';
55
import { config } from 'topcoder-react-utils';
66
import _ from 'lodash';
77
import { getInitials, getSubPageConfiguration } from '../utils/url';
88

9-
let uniqueId = 0;
9+
const headerElId = 'uninav-headerNav';
1010

1111
const TopcoderHeader = ({ auth }) => {
1212
const uniNavInitialized = useRef(false);
@@ -15,20 +15,14 @@ const TopcoderHeader = ({ auth }) => {
1515
const isAuthenticated = !!authToken;
1616
const authURLs = config.HEADER_AUTH_URLS;
1717
const headerRef = useRef();
18-
const [headerId, setHeaderId] = useState(0);
1918

2019
const navigationUserInfo = {
2120
...user,
2221
initials: getInitials(user.firstName, user.lastName),
2322
};
2423

2524
useEffect(() => {
26-
uniqueId += 1;
27-
setHeaderId(uniqueId);
28-
}, []);
29-
30-
useEffect(() => {
31-
if (uniNavInitialized.current || !headerId) {
25+
if (uniNavInitialized.current) {
3226
return;
3327
}
3428

@@ -46,11 +40,10 @@ const TopcoderHeader = ({ auth }) => {
4640
type = urlParams.get('navTool');
4741
}
4842

49-
tcUniNav('init', `headerNav-${headerId}`, {
43+
tcUniNav('init', headerElId, {
5044
type,
5145
toolName: getSubPageConfiguration().toolName,
5246
toolRoot: getSubPageConfiguration().toolRoot,
53-
user: isAuthenticated ? navigationUserInfo : null,
5447
signOut: () => {
5548
window.location = `${config.URL.BASE}/logout?ref=nav`;
5649
},
@@ -61,9 +54,15 @@ const TopcoderHeader = ({ auth }) => {
6154
window.location = `${authURLs.location.replace('%S', retUrl).replace('member?', '#!/member?')}&mode=signUp&regSource=${regSource}`;
6255
},
6356
});
64-
}, [headerId]);
57+
}, []);
58+
59+
useEffect(() => {
60+
tcUniNav('update', headerElId, {
61+
user: isAuthenticated ? navigationUserInfo : null,
62+
});
63+
}, [isAuthenticated, navigationUserInfo]);
6564

66-
return <div id={`headerNav-${headerId}`} ref={headerRef} />;
65+
return <div id={headerElId} ref={headerRef} />;
6766
};
6867

6968
TopcoderHeader.defaultProps = {

0 commit comments

Comments
 (0)