From 9611bebc4568beaed9cd3a7cd8a7256d1d88d014 Mon Sep 17 00:00:00 2001 From: Vasilica Date: Thu, 16 Feb 2023 14:50:04 +0200 Subject: [PATCH 01/28] UN-129 - improve universal-nav ssr placeholder --- package-lock.json | 3 + package.json | 1 + .../containers/TopcoderHeader/index.jsx | 123 +++++++++--------- .../containers/TopcoderHeader/styles.scss | 17 ++- src/shared/utils/url.js | 4 +- 5 files changed, 77 insertions(+), 71 deletions(-) diff --git a/package-lock.json b/package-lock.json index 885b3f2b80..2e2faf81fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25226,6 +25226,9 @@ "x-is-string": "0.1.0" } }, + "uninav-react": { + "version": "git+https://github.com/topcoder-platform/uninav-react.git#1e0ce5e55aca13acad6b50f5b020464a08ed5fa7" + }, "union-class-names": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/union-class-names/-/union-class-names-1.0.0.tgz", diff --git a/package.json b/package.json index 2aa91325e6..753ed75ed1 100644 --- a/package.json +++ b/package.json @@ -168,6 +168,7 @@ "topcoder-react-ui-kit": "2.0.1", "topcoder-react-utils": "0.7.8", "turndown": "^4.0.2", + "uninav-react": "git+https://github.com/topcoder-platform/uninav-react.git#0.0.1", "url-parse": "^1.4.1", "uuid": "^3.3.2", "valid-url": "^1.0.9", diff --git a/src/shared/containers/TopcoderHeader/index.jsx b/src/shared/containers/TopcoderHeader/index.jsx index 074e29e045..25de3cb31f 100644 --- a/src/shared/containers/TopcoderHeader/index.jsx +++ b/src/shared/containers/TopcoderHeader/index.jsx @@ -1,66 +1,51 @@ -/* global tcUniNav */ -import React, { useEffect, useMemo, useRef } from 'react'; +import React, { useMemo } from 'react'; +import PT from 'prop-types'; import { connect } from 'react-redux'; +import { withRouter } from 'react-router-dom'; import { config } from 'topcoder-react-utils'; import LoadingIndicator from 'components/LoadingIndicator'; +import _ from 'lodash'; +import { MarketingNavigation, ToolNavigation } from 'uninav-react'; import { getSubPageConfiguration } from '../../utils/url'; -import { SSRPlaceholder } from '../../utils/SSR'; import './styles.scss'; -let counter = 0; -const headerElIdTmpl = 'uninav-headerNav'; - -const TopcoderHeader = () => { - const uniNavInitialized = useRef(false); +const TopcoderHeader = ({ auth, location }) => { + const user = _.get(auth, 'profile') || {}; + const authToken = _.get(auth, 'tokenV3'); + const isAuthenticated = !!authToken; const authURLs = config.HEADER_AUTH_URLS; - const headerRef = useRef(); - const headerElId = useRef(`${headerElIdTmpl}-${counter}`); - - const navType = useMemo(() => { - if (typeof window === 'undefined') { - return ''; - } - - let { type } = getSubPageConfiguration(); - - // if there's a stored nav type in session storage, retrieve it and overwrite type - const sessionNavType = sessionStorage.getItem('uni-nav[navType]'); - const url = new URL(window.location.href); - - // Only use the set sessionStorage value for navType on the /thrive paths, for now. - // Probably will change in the future... - if (window.location.href.indexOf('/thrive') > -1 && sessionNavType && (sessionNavType === 'tool' || sessionNavType === 'marketing')) { - type = sessionNavType; + const pageCfg = useMemo(() => getSubPageConfiguration(location), [location]); + const isSSR = typeof window === 'undefined'; + + const NavComponent = useMemo(() => { + let { type } = pageCfg; + + if (!isSSR) { + // if there's a stored nav type in session storage, retrieve it and overwrite type + const sessionNavType = sessionStorage.getItem('uni-nav[navType]'); + if (location.pathname.includes() && sessionNavType && (sessionNavType === 'tool' || sessionNavType === 'marketing')) { + type = sessionNavType; + } } // If url contains navTool url parameter. Overwrite settings with parameter. - const urlParams = new URLSearchParams(url.search); - if (urlParams.get('navTool')) { - type = urlParams.get('navTool'); + const navTool = (location.search.match(/navTool=(tool|marketing)/) || [])[1]; + if (navTool) { + type = navTool; } - // store nav type for current session - sessionStorage.setItem('uni-nav[navType]', type); - return type; - }, []); - - useEffect(() => { - if (uniNavInitialized.current) { - return; + if (!isSSR) { + // store nav type for current session + sessionStorage.setItem('uni-nav[navType]', type); } - headerRef.current.id = headerElId.current; + return type === 'marketing' ? MarketingNavigation : ToolNavigation; + }, [pageCfg, location]); - uniNavInitialized.current = true; - counter += 1; + const { signOut, signIn, signUp } = useMemo(() => { + const regSource = (location.pathname || '').split('/')[1]; + const retUrl = encodeURIComponent(isSSR ? location.href : window.location.href); - const regSource = window.location.pathname.split('/')[1]; - const retUrl = encodeURIComponent(window.location.href); - - tcUniNav('init', headerElId.current, { - type: navType, - toolName: getSubPageConfiguration().toolName, - toolRoot: getSubPageConfiguration().toolRoot, - user: 'auto', + return { signOut: () => { window.location = `${config.URL.BASE}/logout?ref=nav`; }, @@ -70,27 +55,39 @@ const TopcoderHeader = () => { signUp: () => { window.location = `${authURLs.location.replace('%S', retUrl).replace('member?', '#!/member?')}&mode=signUp®Source=${regSource}`; }, - }); - }, [navType]); + }; + }, [location]); return ( -
+
+ +
+ +
+
+
); }; +TopcoderHeader.defaultProps = { + auth: {}, + location: typeof window === 'undefined' ? {} : window.location, +}; + +TopcoderHeader.propTypes = { + auth: PT.shape(), + location: PT.shape(), // sent from withRouter +}; const mapStateToProps = state => ({ auth: state.auth, }); -const TopcoderHeaderConnect = connect(mapStateToProps, null)(TopcoderHeader); - -const TopcoderHeaderPlaceholder = () => ( -
- -
-); - -export default SSRPlaceholder()( - TopcoderHeaderConnect, - TopcoderHeaderPlaceholder, -); +export default connect(mapStateToProps, null)(withRouter(TopcoderHeader)); \ No newline at end of file diff --git a/src/shared/containers/TopcoderHeader/styles.scss b/src/shared/containers/TopcoderHeader/styles.scss index 9647bebdf9..0b9a02f2ec 100644 --- a/src/shared/containers/TopcoderHeader/styles.scss +++ b/src/shared/containers/TopcoderHeader/styles.scss @@ -1,10 +1,15 @@ -@import '~styles/mixins'; - .header-container { - min-height: 60px; - background-color: #0c0c0c; + position: relative; } -.header-container-placeholder { - height: 60px; +.loader { + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + + display: flex; + align-items: center; + justify-content: center; } diff --git a/src/shared/utils/url.js b/src/shared/utils/url.js index 2e12de0a77..dd4958fe69 100644 --- a/src/shared/utils/url.js +++ b/src/shared/utils/url.js @@ -164,14 +164,14 @@ export function getInitials(firstName = '', lastName = '') { export const DEFAULT_AVATAR_URL = 'https://images.ctfassets.net/b5f1djy59z3a/4PTwZVSf3W7qgs9WssqbVa/4c51312671a4b9acbdfd7f5e22320b62/default_avatar.svg'; -export const getSubPageConfiguration = () => { +export const getSubPageConfiguration = (location) => { let toolName = 'Community'; let toolRoot = '/'; let loginRedirect = '/'; let type = 'marketing'; let fullFooter = true; - const url = window.location.pathname; + const url = (location || window.location).pathname; if (url.includes('/gigs')) { toolName = 'Gigs'; From f22b5eb8c2c9847a608e4d92ad4bea5688c6b63a Mon Sep 17 00:00:00 2001 From: Vasilica Date: Thu, 16 Feb 2023 15:04:42 +0200 Subject: [PATCH 02/28] fix: add newline to TopcoderHeader file --- src/shared/containers/TopcoderHeader/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/containers/TopcoderHeader/index.jsx b/src/shared/containers/TopcoderHeader/index.jsx index 25de3cb31f..7ea6adaf47 100644 --- a/src/shared/containers/TopcoderHeader/index.jsx +++ b/src/shared/containers/TopcoderHeader/index.jsx @@ -90,4 +90,4 @@ const mapStateToProps = state => ({ auth: state.auth, }); -export default connect(mapStateToProps, null)(withRouter(TopcoderHeader)); \ No newline at end of file +export default connect(mapStateToProps, null)(withRouter(TopcoderHeader)); From 1128d523982b6e535594e4b2ad679e58b0b59c0d Mon Sep 17 00:00:00 2001 From: Justin Gasper Date: Fri, 17 Feb 2023 10:27:53 +1100 Subject: [PATCH 03/28] RDM submission download support --- .../SubmissionRow/SubmissionHistoryRow/index.jsx | 4 +++- .../Submissions/SubmissionRow/index.jsx | 7 +++++-- .../components/challenge-detail/Submissions/index.jsx | 6 ++++-- .../challenge-detail/Winners/Winner/index.jsx | 4 +++- .../components/challenge-detail/Winners/index.jsx | 6 +++++- src/shared/containers/challenge-detail/index.jsx | 4 +++- src/shared/utils/challenge.js | 10 ++++++++++ 7 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/shared/components/challenge-detail/Submissions/SubmissionRow/SubmissionHistoryRow/index.jsx b/src/shared/components/challenge-detail/Submissions/SubmissionRow/SubmissionHistoryRow/index.jsx index 750458887b..5510ef4741 100644 --- a/src/shared/components/challenge-detail/Submissions/SubmissionRow/SubmissionHistoryRow/index.jsx +++ b/src/shared/components/challenge-detail/Submissions/SubmissionRow/SubmissionHistoryRow/index.jsx @@ -21,6 +21,7 @@ const { getService } = services.submissions; export default function SubmissionHistoryRow({ isMM, + isRDM, submission, finalScore, provisionalScore, @@ -81,7 +82,7 @@ export default function SubmissionHistoryRow({
{ - isLoggedIn && isMM + isLoggedIn && (isMM || isRDM) && (numWinners > 0 || challengeStatus === CHALLENGE_STATUS.COMPLETED) && (
Action
@@ -121,6 +122,7 @@ SubmissionHistoryRow.defaultProps = { SubmissionHistoryRow.propTypes = { isMM: PT.bool.isRequired, + isRDM: PT.bool.isRequired, submission: PT.number.isRequired, finalScore: PT.oneOfType([ PT.number, diff --git a/src/shared/components/challenge-detail/Submissions/SubmissionRow/index.jsx b/src/shared/components/challenge-detail/Submissions/SubmissionRow/index.jsx index f4a61b11bb..b2fc9cca9b 100644 --- a/src/shared/components/challenge-detail/Submissions/SubmissionRow/index.jsx +++ b/src/shared/components/challenge-detail/Submissions/SubmissionRow/index.jsx @@ -19,7 +19,7 @@ import SubmissionHistoryRow from './SubmissionHistoryRow'; import style from './style.scss'; export default function SubmissionRow({ - isMM, openHistory, member, submissions, score, toggleHistory, challengeStatus, + isMM, isRDM, openHistory, member, submissions, score, toggleHistory, challengeStatus, isReviewPhaseComplete, finalRank, provisionalRank, onShowPopup, rating, viewAsTable, numWinners, auth, isLoggedIn, }) { @@ -166,7 +166,8 @@ export default function SubmissionRow({ Time
{ - isMM && (numWinners > 0 || challengeStatus === CHALLENGE_STATUS.COMPLETED) && ( + (isMM || isRDM) + && (numWinners > 0 || challengeStatus === CHALLENGE_STATUS.COMPLETED) && (
Action
@@ -185,6 +186,7 @@ export default function SubmissionRow({ 0 || challenge.status === CHALLENGE_STATUS.COMPLETED) - && isMM && isLoggedIn) && ( + && (isMM || isRDM) && isLoggedIn) && (
); }; From 8969b478aa19439aa2774b522d54631673903a43 Mon Sep 17 00:00:00 2001 From: Vasilica Date: Wed, 22 Feb 2023 16:32:50 +0200 Subject: [PATCH 28/28] update uninav loader --- package-lock.json | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 00a82d2785..2ca65ed80a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26337,6 +26337,9 @@ "vfile": "4.2.1" } }, + "uninav-react": { + "version": "git+https://github.com/topcoder-platform/uninav-react.git#3d1c75e56bdba4140ce8341c854ce9a33a2d2c9b" + }, "union-class-names": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/union-class-names/-/union-class-names-1.0.0.tgz", diff --git a/package.json b/package.json index 1627b8a627..0a2d58ff84 100644 --- a/package.json +++ b/package.json @@ -168,7 +168,7 @@ "topcoder-react-ui-kit": "2.0.1", "topcoder-react-utils": "0.7.8", "turndown": "^4.0.2", - "uninav-react": "git+https://github.com/topcoder-platform/uninav-react.git#0.0.1", + "uninav-react": "git+https://github.com/topcoder-platform/uninav-react.git#0.0.2", "url-parse": "^1.4.1", "uuid": "^3.3.2", "valid-url": "^1.0.9",