Skip to content

Commit c187a6b

Browse files
authored
Merge pull request #730 from topcoder-platform/MP-170_blank-profile-sections
MP-170 - add loading state & fix state for experience
2 parents 98a1acf + 606b437 commit c187a6b

File tree

5 files changed

+57
-43
lines changed

5 files changed

+57
-43
lines changed

src/apps/profiles/src/components/EmptySection/EmptySection.module.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@
2828
padding: $sp-15 2*$sp-15;
2929
}
3030

31+
@include ltemd {
32+
&, &:global(.m-lg) {
33+
padding: $sp-8 $sp-6;
34+
}
35+
}
3136
}

src/apps/profiles/src/member-profile/education-and-certifications/EducationAndCertifications.module.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.container {
44
display: flex;
55
flex-direction: column;
6+
padding-bottom: $sp-8;
67

78
.headerWrap {
89
display: flex;
@@ -19,9 +20,15 @@
1920
}
2021
}
2122

23+
.emptyBlock {
24+
display: none;
25+
}
26+
2227
.educationContentWrap {
2328
display: flex;
2429
flex-direction: column;
25-
padding-bottom: $sp-8;
30+
&:empty + .emptyBlock {
31+
display: flex;
32+
}
2633
}
2734
}

src/apps/profiles/src/member-profile/education-and-certifications/EducationAndCertifications.tsx

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Dispatch, FC, SetStateAction, useEffect, useMemo, useState } from 'reac
22
import { useSearchParams } from 'react-router-dom'
33
import { KeyedMutator } from 'swr'
44

5-
import { useMemberTraits, UserProfile, UserTrait, UserTraitIds, UserTraits } from '~/libs/core'
5+
import { MemberTraitsAPI, useMemberTraits, UserProfile, UserTrait, UserTraitIds, UserTraits } from '~/libs/core'
66

77
import { EDIT_MODE_QUERY_PARAM, profileEditModes } from '../../config'
88
import { EditMemberPropertyBtn, EmptySection } from '../../components'
@@ -27,10 +27,7 @@ const EducationAndCertifications: FC<EducationAndCertificationsProps> = (props:
2727
const [isEditMode, setIsEditMode]: [boolean, Dispatch<SetStateAction<boolean>>]
2828
= useState<boolean>(false)
2929

30-
const { data: memberEducationTraits, mutate: mutateTraits }: {
31-
data: UserTraits[] | undefined,
32-
mutate: KeyedMutator<any>,
33-
}
30+
const { data: memberEducationTraits, mutate: mutateTraits, loading }: MemberTraitsAPI
3431
= useMemberTraits(props.profile.handle, { traitIds: UserTraitIds.education })
3532

3633
const memberEducation: UserTrait[] | undefined
@@ -73,28 +70,33 @@ const EducationAndCertifications: FC<EducationAndCertificationsProps> = (props:
7370
</div>
7471

7572
<div className={styles.educationContentWrap}>
76-
{(memberEducation?.length as number) > 0
77-
? memberEducation?.map((education: UserTrait) => (
78-
<EducationCard
79-
key={`${education.schoolCollegeName}-${education.major}`}
80-
education={education}
81-
/>
82-
))
83-
: (
84-
<EmptySection
85-
selfMessage={`
86-
Including your education and certifications enhances the strength
87-
of your profile in comparison to others.
88-
`}
89-
isSelf={canEdit}
90-
>
91-
I&apos;m still building up my education and certifications here at Topcoder.
92-
</EmptySection>
93-
)}
73+
{!loading && (
74+
(memberEducation?.length as number) > 0 && (
75+
memberEducation?.map((education: UserTrait) => (
76+
<EducationCard
77+
key={`${education.schoolCollegeName}-${education.major}`}
78+
education={education}
79+
/>
80+
))
81+
)
82+
)}
9483
</div>
9584

9685
<MemberTCAInfo profile={props.profile} />
9786

87+
{!loading && !memberEducation?.length && (
88+
<EmptySection
89+
className={styles.emptyBlock}
90+
selfMessage={`
91+
Including your education and certifications enhances the strength
92+
of your profile in comparison to others.
93+
`}
94+
isSelf={canEdit}
95+
>
96+
I&apos;m still building up my education and certifications here at Topcoder.
97+
</EmptySection>
98+
)}
99+
98100
{
99101
isEditMode && (
100102
<ModifyEducationModal

src/apps/profiles/src/member-profile/work-expirence/WorkExpirence.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Dispatch, FC, SetStateAction, useEffect, useMemo, useState } from 'react'
22
import { useSearchParams } from 'react-router-dom'
3-
import { KeyedMutator } from 'swr'
43

5-
import { useMemberTraits, UserProfile, UserTrait, UserTraitIds, UserTraits } from '~/libs/core'
4+
import { MemberTraitsAPI, useMemberTraits, UserProfile, UserTrait, UserTraitIds } from '~/libs/core'
65

76
import { EDIT_MODE_QUERY_PARAM, profileEditModes } from '../../config'
87
import { notifyUniNavi } from '../../lib'
@@ -26,10 +25,7 @@ const WorkExpirence: FC<WorkExpirenceProps> = (props: WorkExpirenceProps) => {
2625
const [isEditMode, setIsEditMode]: [boolean, Dispatch<SetStateAction<boolean>>]
2726
= useState<boolean>(false)
2827

29-
const { data: memberWorkExpirenceTraits, mutate: mutateTraits }: {
30-
data: UserTraits[] | undefined,
31-
mutate: KeyedMutator<any>,
32-
}
28+
const { data: memberWorkExpirenceTraits, mutate: mutateTraits, loading }: MemberTraitsAPI
3329
= useMemberTraits(props.profile.handle, { traitIds: UserTraitIds.work })
3430

3531
const workExpirence: UserTrait[] | undefined
@@ -72,18 +68,20 @@ const WorkExpirence: FC<WorkExpirenceProps> = (props: WorkExpirenceProps) => {
7268
</div>
7369

7470
<div className={styles.contentWrap}>
75-
{(workExpirence?.length as number) > 0
76-
? workExpirence?.map((work: UserTrait) => (
77-
<WorkExpirenceCard key={`${work.company}-${work.industry}-${work.position}`} work={work} />
78-
))
79-
: (
80-
<EmptySection
81-
selfMessage='Adding experience enhances the professional appearance of your profile.'
82-
isSelf={canEdit}
83-
>
84-
I&apos;m still building up my experience here at Topcoder.
85-
</EmptySection>
86-
)}
71+
{!loading && (
72+
(workExpirence?.length as number) > 0
73+
? workExpirence?.map((work: UserTrait) => (
74+
<WorkExpirenceCard key={`${work.company}-${work.industry}-${work.position}`} work={work} />
75+
))
76+
: (
77+
<EmptySection
78+
selfMessage='Adding experience enhances the professional appearance of your profile.'
79+
isSelf={canEdit}
80+
>
81+
I&apos;m still building up my experience here at Topcoder.
82+
</EmptySection>
83+
)
84+
)}
8785
</div>
8886

8987
{

src/libs/core/lib/profile/data-providers/useMemberTraits.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { UserTraits } from '../user-traits.model'
66

77
export interface MemberTraitsAPI {
88
data: UserTraits[] | undefined
9+
loading: boolean
910
mutate: KeyedMutator<any>
1011
}
1112

@@ -14,11 +15,12 @@ export interface MemberTraitsQuery {
1415
}
1516

1617
export function useMemberTraits(handle?: string, query?: MemberTraitsQuery): MemberTraitsAPI {
17-
const { data, mutate }: SWRResponse
18+
const { data, mutate, isValidating, error }: SWRResponse
1819
= useSWR(handle ? `${getProfileUrl(handle)}/traits?${qs.stringify(query)}` : undefined)
1920

2021
return {
2122
data,
23+
loading: isValidating && !data && !error,
2224
mutate,
2325
}
2426
}

0 commit comments

Comments
 (0)