File tree Expand file tree Collapse file tree 4 files changed +23
-12
lines changed
apps/profiles/src/member-profile
libs/core/lib/profile/data-providers Expand file tree Collapse file tree 4 files changed +23
-12
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ const MemberProfilePage: FC<{}> = () => {
31
31
if ( routeParams . memberHandle ) {
32
32
profileGetPublicAsync ( routeParams . memberHandle )
33
33
. then ( userProfile => {
34
- setProfile ( userProfile )
34
+ setProfile ( { ... userProfile } as UserProfile )
35
35
setProfileReady ( true )
36
36
} )
37
37
// TODO: NOT FOUND PAGE redirect/dispaly
@@ -41,7 +41,7 @@ const MemberProfilePage: FC<{}> = () => {
41
41
const refreshProfile = useCallback ( ( handle : string ) => (
42
42
profileGetPublicAsync ( handle )
43
43
. then ( userProfile => {
44
- setProfile ( userProfile )
44
+ setProfile ( { ... userProfile } as UserProfile )
45
45
if ( userProfile ) {
46
46
notifyUniNavi ( userProfile )
47
47
triggerSprigSurvey ( userProfile )
Original file line number Diff line number Diff line change @@ -27,7 +27,6 @@ interface ProfilePageLayoutProps {
27
27
}
28
28
29
29
const ProfilePageLayout : FC < ProfilePageLayoutProps > = ( props : ProfilePageLayoutProps ) => (
30
-
31
30
< div className = { styles . container } >
32
31
33
32
< PageTitle > { `${ props . profile . handle } | Community Profile | Topcoder` } </ PageTitle >
@@ -81,7 +80,7 @@ const ProfilePageLayout: FC<ProfilePageLayoutProps> = (props: ProfilePageLayoutP
81
80
</ div >
82
81
< div className = { styles . profileInfoRight } >
83
82
{ props . authProfile ?. handle === props . profile . handle && (
84
- < ProfileCompleteness profile = { props . authProfile } />
83
+ < ProfileCompleteness profile = { props . profile } authProfile = { props . authProfile } />
85
84
) }
86
85
< div className = { styles . sectionWrap } >
87
86
< div className = { styles . skillsWrap } >
Original file line number Diff line number Diff line change 1
- import { FC } from 'react'
1
+ import { FC , useEffect } from 'react'
2
2
3
3
import { useProfileCompleteness , UserProfile } from '~/libs/core'
4
4
5
5
import styles from './ProfileCompleteness.module.scss'
6
6
7
7
interface ProfileCompletenessProps {
8
8
profile : UserProfile
9
+ authProfile : UserProfile
9
10
}
10
11
11
12
const ProfileCompleteness : FC < ProfileCompletenessProps > = props => {
12
- const completed = useProfileCompleteness ( props . profile . handle )
13
- const isLoading = completed === undefined
13
+ const completeness = useProfileCompleteness ( props . profile . handle )
14
+ const completed = completeness . percent
15
+ const isLoading = completeness . isLoading
14
16
const isCompleted = completed === 100
15
17
16
- const isCustomer = props . profile . roles . some ( r => r . indexOf ( ' Customer' ) > - 1 )
18
+ const isCustomer = props . authProfile . roles . some ( r => r . indexOf ( ' Customer' ) > - 1 )
17
19
18
20
const hideCompletenessMeter = isLoading || isCompleted || isCustomer
19
21
22
+ useEffect ( ( ) => { completeness ?. mutate ( ) } , [ props . profile ] )
23
+
20
24
return hideCompletenessMeter ? < > </ > : (
21
25
< div className = { styles . wrap } >
22
26
< strong > Profile: </ strong >
Original file line number Diff line number Diff line change 1
- import useSWR , { SWRResponse } from 'swr'
1
+ import useSWR , { KeyedMutator , SWRResponse } from 'swr'
2
2
3
3
import { getProfileUrl } from '../profile-functions'
4
4
5
- export function useProfileCompleteness ( memberHandle ?: string ) : number | undefined {
6
- const { data } : SWRResponse = useSWR ( `${ getProfileUrl ( memberHandle ?? '' ) } /profileCompleteness` , {
5
+ export function useProfileCompleteness ( memberHandle ?: string ) : {
6
+ isLoading : boolean ,
7
+ mutate : KeyedMutator < any > ,
8
+ percent : number | undefined ,
9
+ } {
10
+ const { data, mutate } : SWRResponse = useSWR ( `${ getProfileUrl ( memberHandle ?? '' ) } /profileCompleteness` , {
7
11
isPaused : ( ) => ! memberHandle ,
8
12
} )
9
13
10
14
const percentComplete = data ?. data ?. percentComplete
11
- return percentComplete === undefined ? percentComplete : ( percentComplete ?? 0 ) * 100
15
+ return {
16
+ isLoading : percentComplete === undefined ,
17
+ mutate,
18
+ percent : ( percentComplete ?? 0 ) * 100 ,
19
+ }
12
20
}
You can’t perform that action at this time.
0 commit comments