Skip to content

Commit 04c3e47

Browse files
Merge pull request #447 from topcoder-platform/TCA-834_fix-uninav-loading
TCA-834 - updates code for uni-nav integration -> dev
2 parents 9427358 + 843acd7 commit 04c3e47

File tree

3 files changed

+45
-89
lines changed

3 files changed

+45
-89
lines changed

src-ts/header/Header.tsx

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import {
66
useCallback,
77
useContext,
88
useEffect,
9+
useMemo,
910
useRef,
1011
useState,
1112
} from 'react'
1213
import { NavigateFunction, useNavigate } from 'react-router-dom'
13-
import { type TcUniNavFn } from 'universal-navigation'
14+
import type { AuthUser as NavAuthUser, TcUniNavFn } from 'universal-navigation'
1415
import classNames from 'classnames'
1516

1617
import { EnvironmentConfig, PageSubheaderPortalId } from '../config'
1718
import {
1819
authUrlLogin,
1920
authUrlLogout,
2021
authUrlSignup,
21-
LoadingSpinner,
2222
profileContext,
2323
ProfileContextData,
2424
routeContext,
@@ -44,6 +44,22 @@ const Header: FC = () => {
4444
const navElementId: string = 'main-nav-el'
4545
const navigate: NavigateFunction = useNavigate()
4646

47+
// userinfo will be an empty object until profileReady=true
48+
// userinfo will be {user: undefined} if user is logged out
49+
// userinfo will have all user's details when user is logged in
50+
const userInfo: {} | undefined | NavAuthUser = useMemo(() => (
51+
!profileReady ? {} : ({
52+
user: profile ? {
53+
email: profile.email,
54+
firstName: profile.firstName,
55+
handle: profile.handle,
56+
lastName: profile.lastName,
57+
photoUrl: profile.photoURL,
58+
userId: profile.userId,
59+
} : undefined,
60+
})
61+
), [profile, profileReady])
62+
4763
const navigationHandler: (request: NavigationRequest) => void
4864
= useCallback((request: NavigationRequest) => {
4965

@@ -60,9 +76,10 @@ const Header: FC = () => {
6076
navigate,
6177
])
6278

79+
// initialize uni-nav elements
6380
useEffect(() => {
6481

65-
if (headerInit.current || !profileReady) {
82+
if (headerInit.current) {
6683
return
6784
}
6885

@@ -73,40 +90,27 @@ const Header: FC = () => {
7390
navElementId,
7491
{
7592
handleNavigation: navigationHandler,
76-
onReady() {
77-
setReady(true)
78-
document.getElementById('root')?.classList.add('app-ready')
79-
},
93+
onReady() { setReady(true) },
8094
signIn() { window.location.href = authUrlLogin() },
8195
signOut() { window.location.href = authUrlLogout },
8296
signUp() { window.location.href = authUrlSignup() },
8397
toolName: activeToolName,
8498
toolRoot: activeToolRoute,
8599
type: 'tool',
86-
user: profile ? {
87-
email: profile.email,
88-
firstName: profile.firstName,
89-
handle: profile.handle,
90-
lastName: profile.lastName,
91-
photoUrl: profile.photoURL,
92-
userId: profile.userId,
93-
} : undefined,
100+
...userInfo,
94101
},
95102
)
96103
}, [
97104
activeToolName,
98105
activeToolRoute,
99106
navigationHandler,
100-
profile,
107+
userInfo,
101108
profileReady,
102109
])
103110

111+
// update uni-nav's tool details
104112
useEffect(() => {
105113

106-
if (!profileReady) {
107-
return
108-
}
109-
110114
tcUniNav(
111115
'update',
112116
navElementId,
@@ -118,16 +122,33 @@ const Header: FC = () => {
118122
}, [
119123
activeToolName,
120124
activeToolRoute,
125+
])
126+
127+
// update uni-nav's user/auth details
128+
useEffect(() => {
129+
130+
if (!profileReady) {
131+
return
132+
}
133+
134+
tcUniNav(
135+
'update',
136+
navElementId,
137+
{
138+
...userInfo,
139+
},
140+
)
141+
}, [
121142
profileReady,
143+
userInfo,
122144
])
123145

124146
return (
125147
<>
126-
<LoadingSpinner hide={ready} />
127148
<div id={navElementId} />
128149
<div
129150
id={PageSubheaderPortalId}
130-
className={classNames('full-width-relative')}
151+
className={classNames('full-width-relative', !ready && 'hidden')}
131152
/>
132153
</>
133154
)
Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +0,0 @@
1-
@import '../styles/includes';
2-
@import '../styles/typography';
3-
4-
.footer-wrap {
5-
height: $footer-height;
6-
border-top: $border-xs solid $black-10;
7-
8-
:global(#root:not(.app-ready)) & {
9-
display: none;
10-
}
11-
}
12-
13-
.footer-inner {
14-
display: flex;
15-
16-
align-items: center;
17-
padding: $space-lg 0;
18-
max-width: $xxl-min;
19-
margin: 0 auto;
20-
21-
@include pagePaddings;
22-
23-
@extend .body-ultra-small;
24-
color: $black-100;
25-
26-
@include ltesm {
27-
flex-direction: column;
28-
gap: $space-sm;
29-
}
30-
}
31-
32-
.utils {
33-
display: flex;
34-
align-items: center;
35-
gap: $space-lg;
36-
37-
> div > * + * {
38-
margin-left: $space-lg;
39-
}
40-
41-
@include ltesm {
42-
flex-direction: column;
43-
gap: $space-sm;
44-
45-
> div > * + * {
46-
margin-left: $space-sm;
47-
}
48-
}
49-
}
50-
51-
.social {
52-
display: flex;
53-
align-items: center;
54-
gap: $space-xs;
55-
color: $black-60;
56-
57-
margin-left: auto;
58-
59-
a {
60-
display: flex;
61-
}
62-
@include ltesm {
63-
margin-right: auto;
64-
}
65-
}

src-ts/lib/page-footer/PageFooter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FC } from 'react'
2+
import type { TcUniNavFn } from 'universal-navigation'
23

3-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4-
declare let tcUniNav: any
4+
declare let tcUniNav: TcUniNavFn
55

66
const PageFooter: FC<{}> = () => {
77

0 commit comments

Comments
 (0)