Skip to content

Commit ff16aab

Browse files
authored
Merge pull request #6796 from topcoder-platform/PROD-3881_universal_nav
PROD-3881 universal nav
2 parents 1e0b711 + c63d06c commit ff16aab

File tree

3 files changed

+58
-32
lines changed

3 files changed

+58
-32
lines changed

__tests__/shared/components/__snapshots__/TopcoderFooter.jsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
exports[`Matches shallow shapshot 1`] = `
44
<div
5-
id="uninav-footerNav"
5+
id="uninav-footerNav-0"
66
/>
77
`;
Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
11
/* global tcUniNav */
2-
import React, { useEffect, useRef } from 'react';
2+
import React, { useEffect, useMemo, useRef } from 'react';
33
import { getSubPageConfiguration } from '../../utils/url';
44

5-
const footerElId = 'uninav-footerNav';
5+
let counter = 0;
6+
const footerElIdTmpl = 'uninav-footerNav';
67

78
export default function TopcoderFooter() {
89
const footerRef = useRef();
910
const footerInitialized = useRef(false);
11+
const footerElId = useRef(`${footerElIdTmpl}-${counter}`);
12+
13+
const navType = useMemo(() => {
14+
let { type } = getSubPageConfiguration();
15+
16+
// If url contains navTool url parameter. Overwrite settings with parameter.
17+
const url = new URL(window.location.href);
18+
const urlParams = new URLSearchParams(url.search);
19+
if (urlParams.get('navTool')) {
20+
type = urlParams.get('navTool');
21+
}
22+
23+
const sessionNavType = sessionStorage.getItem('uni-nav[navType]');
24+
if (sessionNavType && (sessionNavType === 'tool' || sessionNavType === 'marketing')) {
25+
type = sessionNavType;
26+
}
27+
28+
return type;
29+
}, []);
1030

1131
useEffect(() => {
1232
if (footerInitialized.current) {
1333
return;
1434
}
1535

1636
footerInitialized.current = true;
37+
counter += 1;
1738

18-
let { fullFooter } = getSubPageConfiguration();
19-
20-
// If url contains navTool url parameter. Overwrite settings with parameter.
21-
const url = new URL(window.location.href);
22-
const urlParams = new URLSearchParams(url.search);
23-
const navToolParam = urlParams.get('navTool');
24-
if (navToolParam) {
25-
fullFooter = navToolParam !== 'tool';
26-
}
27-
28-
tcUniNav('init', footerElId, {
29-
fullFooter,
39+
tcUniNav('init', footerElId.current, {
40+
fullFooter: navType !== 'tool',
3041
type: 'footer',
3142
});
3243
}, []);
3344

34-
return <div id={footerElId} ref={footerRef} />;
45+
return <div id={footerElId.current} ref={footerRef} />;
3546
}

src/shared/containers/TopcoderHeader.jsx

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* global tcUniNav */
2-
import React, { useEffect, useRef } from 'react';
2+
import React, { useEffect, useMemo, 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-
const headerElId = 'uninav-headerNav';
9+
let counter = 0;
10+
const headerElIdTmpl = 'uninav-headerNav';
1011

1112
const TopcoderHeader = ({ auth }) => {
1213
const uniNavInitialized = useRef(false);
@@ -15,6 +16,28 @@ const TopcoderHeader = ({ auth }) => {
1516
const isAuthenticated = !!authToken;
1617
const authURLs = config.HEADER_AUTH_URLS;
1718
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+
}, []);
1841

1942
const navigationUserInfo = {
2043
...user,
@@ -27,21 +50,13 @@ const TopcoderHeader = ({ auth }) => {
2750
}
2851

2952
uniNavInitialized.current = true;
53+
counter += 1;
3054

3155
const regSource = window.location.pathname.split('/')[1];
3256
const retUrl = encodeURIComponent(window.location.href);
3357

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,
58+
tcUniNav('init', headerElId.current, {
59+
type: navType,
4560
toolName: getSubPageConfiguration().toolName,
4661
toolRoot: getSubPageConfiguration().toolRoot,
4762
signOut: () => {
@@ -54,15 +69,15 @@ const TopcoderHeader = ({ auth }) => {
5469
window.location = `${authURLs.location.replace('%S', retUrl).replace('member?', '#!/member?')}&mode=signUp&regSource=${regSource}`;
5570
},
5671
});
57-
}, []);
72+
}, [navType]);
5873

5974
useEffect(() => {
60-
tcUniNav('update', headerElId, {
75+
tcUniNav('update', headerElId.current, {
6176
user: isAuthenticated ? navigationUserInfo : null,
6277
});
6378
}, [isAuthenticated, navigationUserInfo]);
6479

65-
return <div id={headerElId} ref={headerRef} />;
80+
return <div id={headerElId.current} ref={headerRef} />;
6681
};
6782

6883
TopcoderHeader.defaultProps = {

0 commit comments

Comments
 (0)