1
+ import { useMemo } from 'react' ;
1
2
import * as Sentry from '@sentry/react' ;
2
3
3
4
import TeamAvatar from 'sentry/components/avatar/teamAvatar' ;
4
5
import UserAvatar from 'sentry/components/avatar/userAvatar' ;
5
- import LoadingIndicator from 'sentry/components/loadingIndicator' ;
6
- import MemberListStore from 'sentry/stores/memberListStore' ;
6
+ import Placeholder from 'sentry/components/placeholder' ;
7
7
import type { Actor } from 'sentry/types' ;
8
+ import { useMembers } from 'sentry/utils/useMembers' ;
8
9
import { useTeamsById } from 'sentry/utils/useTeamsById' ;
9
10
10
11
import type { BaseAvatarProps } from './baseAvatar' ;
@@ -24,12 +25,32 @@ function LoadTeamAvatar({
24
25
const team = teams . find ( t => t . id === teamId ) ;
25
26
26
27
if ( isLoading ) {
27
- return < LoadingIndicator mini /> ;
28
+ const size = `${ props . size } px` ;
29
+ return < Placeholder width = { size } height = { size } /> ;
28
30
}
29
31
30
32
return < TeamAvatar team = { team } { ...props } /> ;
31
33
}
32
34
35
+ /**
36
+ * Wrapper to assist loading the user from api or store
37
+ */
38
+ function LoadMemberAvatar ( {
39
+ userId,
40
+ ...props
41
+ } : { userId : string } & Omit < React . ComponentProps < typeof UserAvatar > , 'team' > ) {
42
+ const ids = useMemo ( ( ) => [ userId ] , [ userId ] ) ;
43
+ const { members, fetching} = useMembers ( { ids} ) ;
44
+ const user = members . find ( u => u . id === userId ) ;
45
+
46
+ if ( fetching ) {
47
+ const size = `${ props . size } px` ;
48
+ return < Placeholder shape = "circle" width = { size } height = { size } /> ;
49
+ }
50
+
51
+ return < UserAvatar user = { user } { ...props } /> ;
52
+ }
53
+
33
54
function ActorAvatar ( { size = 24 , hasTooltip = true , actor, ...props } : Props ) {
34
55
const otherProps = {
35
56
size,
@@ -38,8 +59,7 @@ function ActorAvatar({size = 24, hasTooltip = true, actor, ...props}: Props) {
38
59
} ;
39
60
40
61
if ( actor . type === 'user' ) {
41
- const user = actor . id ? MemberListStore . getById ( actor . id ) ?? actor : actor ;
42
- return < UserAvatar user = { user } { ...otherProps } /> ;
62
+ return < LoadMemberAvatar userId = { actor . id } { ...otherProps } /> ;
43
63
}
44
64
45
65
if ( actor . type === 'team' ) {
0 commit comments