Skip to content

Commit ae88227

Browse files
Merge pull request #423 from topcoder-platform/PROD-3234_dev-center
PROD-3234 Add Spinner while Header Loads -> PROD-3115_uni-nav
2 parents ef495ae + 1ddbfd3 commit ae88227

File tree

8 files changed

+41
-34
lines changed

8 files changed

+41
-34
lines changed

src-ts/App.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Dispatch, FC, ReactElement, SetStateAction, useContext, useEffect, useState } from 'react'
1+
import { FC, ReactElement, useContext } from 'react'
22
import { Routes } from 'react-router-dom'
33
import { toast, ToastContainer } from 'react-toastify'
44

@@ -7,22 +7,11 @@ import { routeContext, RouteContextData } from './lib'
77

88
const App: FC<{}> = () => {
99

10-
const [ready, setReady]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)
1110
const { allRoutes, getRouteElement }: RouteContextData = useContext(routeContext)
1211

1312
const routeElements: Array<ReactElement> = allRoutes
1413
.map(route => getRouteElement(route))
1514

16-
useEffect(() => {
17-
setReady(true)
18-
}, [])
19-
20-
useEffect(() => {
21-
if (ready) {
22-
document.getElementById('root')?.classList.add('app-ready');
23-
}
24-
}, [ready]);
25-
2615
return (
2716
<>
2817
<Header />

src-ts/config/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export enum ToolTitle {
66
work = 'Self-Service',
77
}
88

9-
export const PagePortalId: string = 'page-subheader-portal-el'
9+
export const PageSubheaderPortalId: string = 'page-subheader-portal-el'

src-ts/header/Header.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import {
1010
} from 'react'
1111
import classNames from 'classnames'
1212

13-
import { EnvironmentConfig, PagePortalId } from '../config'
13+
import { EnvironmentConfig, PageSubheaderPortalId } from '../config'
1414
import {
1515
authUrlLogin,
1616
authUrlLogout,
1717
authUrlSignup,
18+
LoadingSpinner,
1819
profileContext,
1920
ProfileContextData,
2021
routeContext,
@@ -29,7 +30,7 @@ UniNavSnippet(EnvironmentConfig.UNIVERSAL_NAV.URL)
2930

3031
const Header: FC = () => {
3132

32-
const { activeToolName }: RouteContextData = useContext(routeContext)
33+
const { activeToolName, activeToolRoute }: RouteContextData = useContext(routeContext)
3334
const { profile, initialized: profileReady }: ProfileContextData = useContext(profileContext)
3435
const [ready, setReady]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
3536
const headerInit: MutableRefObject<boolean> = useRef(false)
@@ -44,7 +45,7 @@ const Header: FC = () => {
4445
headerInit.current = true
4546

4647
tcUniNav(
47-
'tool',
48+
'init',
4849
navElementId,
4950
{
5051
onReady() {
@@ -55,6 +56,8 @@ const Header: FC = () => {
5556
signOut() { window.location.href = authUrlLogout },
5657
signUp() { window.location.href = authUrlSignup() },
5758
toolName: activeToolName,
59+
toolRoute: activeToolRoute,
60+
type: 'tool',
5861
user: profileReady && profile ? {
5962
handle: profile.handle,
6063
initials: `${profile.firstName.charAt(0)}${profile.lastName.charAt(0)}`,
@@ -65,15 +68,18 @@ const Header: FC = () => {
6568
)
6669
}, [
6770
activeToolName,
71+
activeToolRoute,
6872
profileReady,
69-
profile])
73+
profile,
74+
])
7075

7176
return (
7277
<>
78+
<LoadingSpinner hide={ready} />
7379
<div id={navElementId} />
7480
<div
75-
id={PagePortalId}
76-
className={classNames('full-width-relative', !ready && 'hidden')}
81+
id={PageSubheaderPortalId}
82+
className={classNames('full-width-relative')}
7783
/>
7884
</>
7985
)

src-ts/lib/breadcrumb/Breadcrumb.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FC } from 'react'
22
import { createPortal } from 'react-dom'
33

4-
import { PagePortalId } from '../../config'
4+
import { PageSubheaderPortalId } from '../../config'
55

66
import { BreadcrumbItem, BreadcrumbItemModel } from './breadcrumb-item'
77
import styles from './Breadcrumb.module.scss'
@@ -11,7 +11,7 @@ interface BreadcrumbProps {
1111
}
1212

1313
const Breadcrumb: FC<BreadcrumbProps> = (props: BreadcrumbProps) => {
14-
const portalRootEl: HTMLElement | null = document.getElementById(PagePortalId)
14+
const portalRootEl: HTMLElement | null = document.getElementById(PageSubheaderPortalId)
1515

1616
if (!portalRootEl) {
1717
return <></>

src-ts/lib/route-provider/route-context-data.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PlatformRoute } from './platform-route.model'
44

55
export interface RouteContextData {
66
activeToolName?: string
7+
activeToolRoute?: string
78
allRoutes: Array<PlatformRoute>
89
getChildren: (parent: string) => Array<PlatformRoute>
910
getChildRoutes: (parent: string) => Array<ReactElement>

src-ts/lib/route-provider/route.provider.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,25 @@ export const RouteProvider: FC<RouteProviderProps> = (props: RouteProviderProps)
5555
// a. for customers and the user is a customer
5656
// b. for members and the user is a member
5757
// c. the active tool in the app (in case someone deep-links to it)
58+
let activeRoute: PlatformRoute | undefined
5859
const toolsRoutesForNav: Array<PlatformRoute> = toolsRoutes
59-
.filter(route => !!route.title
60-
&& !route.hidden
61-
&& (
62-
(
63-
(!route.customerOnly || !!profile?.isCustomer)
64-
&& (!route.memberOnly || !!profile?.isMember)
60+
.filter(route => {
61+
62+
const isActive: boolean = routeIsActiveTool(location.pathname, route)
63+
if (isActive) {
64+
activeRoute = route
65+
}
66+
67+
return !!route.title
68+
&& !route.hidden
69+
&& (
70+
(
71+
(!route.customerOnly || !!profile?.isCustomer)
72+
&& (!route.memberOnly || !!profile?.isMember)
73+
)
74+
|| isActive
6575
)
66-
|| routeIsActiveTool(location.pathname, route)
67-
))
76+
})
6877

6978
const utilsRoutes: Array<PlatformRoute> = props.utilsRoutes.filter(route => !route.disabled)
7079
allRoutes = [
@@ -77,8 +86,10 @@ export const RouteProvider: FC<RouteProviderProps> = (props: RouteProviderProps)
7786
: profile.isCustomer
7887
? props.rootCustomer
7988
: props.rootMember
89+
8090
const contextData: RouteContextData = {
81-
activeToolName: allRoutes.find(r => routeIsActiveTool(location.pathname, r))?.title,
91+
activeToolName: activeRoute?.title,
92+
activeToolRoute: !!activeRoute ? `https://${window.location.hostname}${activeRoute.route}` : undefined,
8293
allRoutes,
8394
getChildren,
8495
getChildRoutes,

src-ts/tools/learn/my-learning/MyLearning.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Dispatch, FC, ReactNode, SetStateAction, useContext, useMemo, useState } from 'react'
22

3-
import { PagePortalId } from '../../../config'
3+
import { PageSubheaderPortalId } from '../../../config'
44
import {
55
Breadcrumb,
66
BreadcrumbItemModel,
@@ -83,7 +83,7 @@ const MyLearning: FC<{}> = () => {
8383
<div className={styles.wrap}>
8484
<LoadingSpinner hide={ready} className={styles['loading-spinner']} />
8585

86-
<Portal portalId={PagePortalId}>
86+
<Portal portalId={PageSubheaderPortalId}>
8787
<div className={styles['hero-wrap']}>
8888
<WaveHero
8989
title='my learning'

src-ts/tools/learn/welcome/WelcomePage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FC } from 'react'
22
import classNames from 'classnames'
33

4-
import { PagePortalId } from '../../../config'
4+
import { PageSubheaderPortalId } from '../../../config'
55
import { ContentLayout, LoadingSpinner, Portal } from '../../../lib'
66
import {
77
AllCertificationsProviderData,
@@ -29,7 +29,7 @@ const WelcomePage: FC = () => {
2929

3030
<div className={classNames(styles.wrap, 'full-height-frame')}>
3131

32-
<Portal portalId={PagePortalId}>
32+
<Portal portalId={PageSubheaderPortalId}>
3333
<div className={styles['hero-wrap']}>
3434
<WaveHero
3535
title={(

0 commit comments

Comments
 (0)