Skip to content

Commit 75ed67c

Browse files
committed
Revert "fix: uninav on sub pages, persist type in session storage"
This reverts commit c5e0a03.
1 parent 483cb1c commit 75ed67c

File tree

3 files changed

+32
-66
lines changed

3 files changed

+32
-66
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-0"
5+
id="uninav-footerNav"
66
/>
77
`;
Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,35 @@
11
/* global tcUniNav */
2-
import React, { useEffect, useMemo, useRef } from 'react';
2+
import React, { useEffect, useRef } from 'react';
33
import { getSubPageConfiguration } from '../../utils/url';
44

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

87
export default function TopcoderFooter() {
98
const footerRef = useRef();
109
const footerInitialized = useRef(false);
11-
const footerElId = useRef(`${footerElIdTmpl}-${counter}`);
12-
13-
const navType = useMemo(() => {
14-
let { type } = getSubPageConfiguration();
15-
16-
if (typeof window === 'undefined') {
17-
return type;
18-
}
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-
if (urlParams.get('navTool')) {
24-
type = urlParams.get('navTool');
25-
}
26-
27-
const sessionNavType = sessionStorage.getItem('uni-nav[navType]');
28-
if (sessionNavType && (sessionNavType === 'tool' || sessionNavType === 'marketing')) {
29-
type = sessionNavType;
30-
}
31-
32-
return type;
33-
}, []);
3410

3511
useEffect(() => {
3612
if (footerInitialized.current) {
3713
return;
3814
}
3915

4016
footerInitialized.current = true;
41-
counter += 1;
4217

43-
tcUniNav('init', footerElId.current, {
44-
fullFooter: navType !== 'tool',
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,
4530
type: 'footer',
4631
});
4732
}, []);
4833

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

src/shared/containers/TopcoderHeader.jsx

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

1211
const TopcoderHeader = ({ auth }) => {
1312
const uniNavInitialized = useRef(false);
@@ -16,32 +15,6 @@ const TopcoderHeader = ({ auth }) => {
1615
const isAuthenticated = !!authToken;
1716
const authURLs = config.HEADER_AUTH_URLS;
1817
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-
}, []);
4518

4619
const navigationUserInfo = {
4720
...user,
@@ -54,13 +27,21 @@ const TopcoderHeader = ({ auth }) => {
5427
}
5528

5629
uniNavInitialized.current = true;
57-
counter += 1;
5830

5931
const regSource = window.location.pathname.split('/')[1];
6032
const retUrl = encodeURIComponent(window.location.href);
6133

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,
6445
toolName: getSubPageConfiguration().toolName,
6546
toolRoot: getSubPageConfiguration().toolRoot,
6647
signOut: () => {
@@ -73,15 +54,15 @@ const TopcoderHeader = ({ auth }) => {
7354
window.location = `${authURLs.location.replace('%S', retUrl).replace('member?', '#!/member?')}&mode=signUp&regSource=${regSource}`;
7455
},
7556
});
76-
}, [navType]);
57+
}, []);
7758

7859
useEffect(() => {
79-
tcUniNav('update', headerElId.current, {
60+
tcUniNav('update', headerElId, {
8061
user: isAuthenticated ? navigationUserInfo : null,
8162
});
8263
}, [isAuthenticated, navigationUserInfo]);
8364

84-
return <div id={headerElId.current} ref={headerRef} />;
65+
return <div id={headerElId} ref={headerRef} />;
8566
};
8667

8768
TopcoderHeader.defaultProps = {

0 commit comments

Comments
 (0)