Changeset View
Changeset View
Standalone View
Standalone View
native/avatars/user-avatar.react.js
// @flow | // @flow | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import { | import { | ||||
getAvatarForUser, | getAvatarForUser, | ||||
useENSResolvedAvatar, | useENSResolvedAvatar, | ||||
} from 'lib/shared/avatar-utils.js'; | } from 'lib/shared/avatar-utils.js'; | ||||
import type { GenericUserInfoWithAvatar } from 'lib/types/avatar-types.js'; | |||||
import Avatar from './avatar.react.js'; | import Avatar from './avatar.react.js'; | ||||
import { useSelector } from '../redux/redux-utils.js'; | import { useSelector } from '../redux/redux-utils.js'; | ||||
type Props = { | type Size = 'micro' | 'small' | 'large' | 'profile'; | ||||
+userID: ?string, | type Props = | ||||
+size: 'micro' | 'small' | 'large' | 'profile', | | { +userID: ?string, +size: Size } | ||||
}; | | { +userInfo: ?GenericUserInfoWithAvatar, +size: Size }; | ||||
function UserAvatar(props: Props): React.Node { | function UserAvatar(props: Props): React.Node { | ||||
const { userID, size } = props; | const { userID, userInfo: userInfoProp, size } = props; | ||||
const currentUserInfo = useSelector(state => state.currentUserInfo); | const currentUserInfo = useSelector(state => state.currentUserInfo); | ||||
const userInfo = useSelector(state => | const userInfo = useSelector(state => | ||||
userID ? state.userStore.userInfos[userID] : null, | userID ? state.userStore.userInfos[userID] : userInfoProp, | ||||
); | ); | ||||
const avatarUserInfo = | const avatarUserInfo = | ||||
userID === currentUserInfo?.id ? currentUserInfo : userInfo; | userID === currentUserInfo?.id ? currentUserInfo : userInfo; | ||||
const avatarInfo = getAvatarForUser(avatarUserInfo); | const avatarInfo = getAvatarForUser(avatarUserInfo); | ||||
const resolvedUserAvatar = useENSResolvedAvatar(avatarInfo, userInfo); | const resolvedUserAvatar = useENSResolvedAvatar(avatarInfo, userInfo); | ||||
return <Avatar size={size} avatarInfo={resolvedUserAvatar} />; | return <Avatar size={size} avatarInfo={resolvedUserAvatar} />; | ||||
} | } | ||||
export default UserAvatar; | export default UserAvatar; |