-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f189eb
commit 8972dfd
Showing
4 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React, { useMemo } from 'react'; | ||
import { useCachedUserInfo } from '@shared/hooks/cache'; | ||
import styled from 'styled-components'; | ||
import Avatar from '../Avatar'; | ||
import config from '@shared/project.config'; | ||
import _isEmpty from 'lodash/isEmpty'; | ||
|
||
const Container = styled.div` | ||
display: flex; | ||
max-width: 240px; | ||
.avatar { | ||
overflow: hidden; | ||
border: 1px solid white; | ||
> img { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
} | ||
.info { | ||
flex: 1; | ||
margin-left: 10px; | ||
overflow: hidden; | ||
} | ||
`; | ||
|
||
interface Props { | ||
userUUID: string; | ||
} | ||
const PopoverUserInfo: React.FC<Props> = React.memo((props) => { | ||
const userInfo = useCachedUserInfo(props.userUUID); | ||
|
||
const name = useMemo(() => userInfo.nickname ?? userInfo.username ?? '', [ | ||
userInfo.nickname, | ||
userInfo.username, | ||
]); | ||
|
||
const avatar = useMemo( | ||
() => | ||
_isEmpty(userInfo.avatar) | ||
? config.defaultImg.getUser(name) | ||
: userInfo.avatar, | ||
[userInfo.avatar] | ||
); | ||
|
||
return ( | ||
<Container> | ||
<div className="avatar"> | ||
<Avatar size="large" src={avatar} name={name} /> | ||
</div> | ||
<div className="info"> | ||
<div> | ||
<span>用户名: </span> | ||
<span>{name}</span> | ||
</div> | ||
<div> | ||
<span>性别: </span> | ||
<span>{userInfo.sex}</span> | ||
</div> | ||
<div> | ||
<span>签名: </span> | ||
<p>{userInfo.sign}</p> | ||
</div> | ||
</div> | ||
</Container> | ||
); | ||
}); | ||
PopoverUserInfo.displayName = 'PopoverUserInfo'; | ||
|
||
export default PopoverUserInfo; |