Skip to content

Commit 7eb6857

Browse files
Merge pull request #248 from topcoder-platform/PROD-2740_loading
PROD-2740 Update loading spinner -> dev
2 parents 2d4883d + 91a2df6 commit 7eb6857

File tree

22 files changed

+118
-49
lines changed

22 files changed

+118
-49
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Link } from 'react-router-dom'
2+
import { toast, ToastContent } from 'react-toastify'
3+
4+
import { contactSupportPath } from '../../contact-support-form'
5+
import { logError } from '../logging-functions'
6+
7+
export function handle(error: any, errString?: string): void {
8+
9+
logError(error)
10+
11+
const errorContent: ToastContent = (
12+
<>
13+
<p>
14+
{errString ?? error.response?.data?.result?.content ?? error.message ?? error}
15+
{' '}
16+
Please try again later or
17+
{' '}
18+
<Link
19+
className='font-link-blue-dark'
20+
to={contactSupportPath}
21+
>
22+
Contact Support
23+
</Link>.
24+
</p>
25+
</>
26+
)
27+
28+
toast.error(errorContent)
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { handle as errorHandle } from './error.functions'

src-ts/lib/functions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export {
66
authUrlLogout,
77
authUrlSignup,
88
} from './authentication-functions'
9+
export * from './error-functions'
910
export * from './file-functions'
1011
export * from './logging-functions'
1112
export * from './text-format-functions'

src-ts/lib/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ export {
1010
authUrl,
1111
authUrlLogin,
1212
authUrlLogout,
13+
authUrlSignup,
14+
errorHandle,
1315
fileCreateFromCanvas,
1416
fileDownloadBlob,
1517
fileDownloadCanvasAsImage,
18+
logError,
1619
logInfo,
1720
logInitialize,
1821
textFormatDateLocaleShortString,

src-ts/lib/loading-spinner/LoadingSpinner.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ import styles from './LoadingSpinner.module.scss'
1111

1212
export interface LoadingSpinnerProps {
1313
className?: string
14-
show?: boolean
14+
hide?: boolean
1515
}
1616

17-
const LoadingSpinner: FC<LoadingSpinnerProps> = ({ show = false, className }: LoadingSpinnerProps) => {
17+
const LoadingSpinner: FC<LoadingSpinnerProps> = ({ hide, className }: LoadingSpinnerProps) => {
18+
19+
if (!!hide) {
20+
return <></>
21+
}
22+
1823
return (
19-
<div className={classNames(styles['loading-spinner'], styles[show ? 'show' : 'hide'], className)}>
24+
<div className={classNames(styles['loading-spinner'], styles.show, className)}>
2025
<PuffLoader color={'#2196f3'} loading={true} size={100} />
2126
</div>
2227
)

src-ts/lib/styles/_layout.scss

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,27 @@ hr {
3030
display: none;
3131
}
3232

33+
.full-height-frame {
34+
position: relative;
35+
flex: 1 1 auto;
36+
display: flex;
37+
flex-direction: column;
38+
}
3339

3440
.mobile-hide {
35-
&.mobile-hide.mobile-hide { // increase specificity without using !important
41+
42+
// increase specificity without using !important
43+
&.mobile-hide.mobile-hide {
3644
@include ltemd {
3745
display: none;
3846
}
3947
}
4048
}
4149

4250
.desktop-hide {
43-
&.desktop-hide.desktop-hide { // increase specificity without using !important
51+
52+
// increase specificity without using !important
53+
&.desktop-hide.desktop-hide {
4454
@include gtelg {
4555
display: none;
4656
}

src-ts/tools/learn/course-certificate/certificate-view/CertificateView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const CertificateView: FC<CertificateViewProps> = (props: CertificateViewProps)
140140

141141
return (
142142
<>
143-
{!ready && <LoadingSpinner show />}
143+
<LoadingSpinner hide={ready} />
144144

145145
{readyAndCompletedCertification && (
146146
<div className={styles['wrap']}>

src-ts/tools/learn/course-certificate/my-certificate/MyCertificate.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ const MyCertificate: FC<{}> = () => {
2323
}, [coursePath, navigate])
2424

2525
useEffect(() => {
26-
if (profileReady && !profile) {
27-
navigateToCourse()
28-
}
26+
if (profileReady && !profile) {
27+
navigateToCourse()
28+
}
2929
}, [profileReady, profile, navigateToCourse])
3030

3131
return (
3232
<>
33-
{!profileReady && <LoadingSpinner show />}
33+
<LoadingSpinner hide={profileReady} />
3434

3535
{profileReady && profile && (
3636
<CertificateView

src-ts/tools/learn/course-certificate/user-certificate/UserCertificate.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@ import CertificateView from '../certificate-view/CertificateView'
1111
import styles from './UserCertificate.module.scss'
1212

1313
const UserCertificate: FC<{}> = () => {
14+
1415
const wrapElRef: MutableRefObject<HTMLElement | any> = useRef()
1516
const routeParams: Params<string> = useParams()
1617
const [profile, setProfile]: [
17-
UserProfile|undefined,
18-
Dispatch<SetStateAction<UserProfile|undefined>>
18+
UserProfile | undefined,
19+
Dispatch<SetStateAction<UserProfile | undefined>>
1920
] = useState()
20-
const [profileReady, setProfileReady]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)
21+
const [profileReady, setProfileReady]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
2122

2223
const providerParam: string = routeParams.provider ?? ''
2324
const certificationParam: string = routeParams.certification ?? ''
2425

2526
useEffect(() => {
2627
if (routeParams.memberHandle) {
27-
profileGetAsync(routeParams.memberHandle).then((userProfile) => {
28-
setProfile(userProfile)
29-
setProfileReady(true)
30-
})
28+
profileGetAsync(routeParams.memberHandle)
29+
.then((userProfile) => {
30+
setProfile(userProfile)
31+
setProfileReady(true)
32+
})
3133
}
3234
}, [routeParams.memberHandle, setProfileReady])
3335

@@ -39,23 +41,23 @@ const UserCertificate: FC<{}> = () => {
3941

4042
[].forEach.call(el.parentElement?.children ?? [], (c: HTMLElement) => {
4143
if (c !== el) {
42-
Object.assign(c.style, {display: 'none'})
44+
Object.assign(c.style, { display: 'none' })
4345
}
4446
})
4547
el.classList.add(styles['full-screen-cert'])
4648
})
4749

4850
return (
4951
<>
50-
{!profileReady && <LoadingSpinner show />}
52+
<LoadingSpinner hide={profileReady} />
5153

5254
{profileReady && profile && (
5355
<div ref={wrapElRef}>
5456
<CertificateView
5557
certification={certificationParam}
5658
profile={profile}
5759
provider={providerParam}
58-
onCertificationNotCompleted={() => {}}
60+
onCertificationNotCompleted={() => { }}
5961
hideActions
6062
/>
6163
</div>

src-ts/tools/learn/course-completed/CourseCompletedPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const CourseCompletedPage: FC<{}> = () => {
8585

8686
return (
8787
<>
88-
{!ready && <LoadingSpinner show />}
88+
<LoadingSpinner hide={ready} />
8989

9090
{ready && courseData && (
9191
<>

0 commit comments

Comments
 (0)