2020-02-21 00:57:29 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
2020-06-13 02:51:39 +01:00
|
|
|
import debounce from 'lodash.debounce'
|
2020-04-24 04:17:27 +01:00
|
|
|
import { me } from '../initial_state'
|
|
|
|
import {
|
|
|
|
CX,
|
|
|
|
POPOVER_USER_INFO,
|
|
|
|
} from '../constants'
|
2020-02-28 15:20:47 +00:00
|
|
|
import { openPopover, closePopover } from '../actions/popover'
|
2020-02-21 00:57:29 +00:00
|
|
|
import Icon from './icon'
|
2020-04-24 04:17:27 +01:00
|
|
|
import Text from './text'
|
2020-02-28 15:20:47 +00:00
|
|
|
|
2020-04-11 23:29:19 +01:00
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
2020-03-11 23:56:18 +00:00
|
|
|
openUserInfoPopover(props) {
|
2020-04-24 04:17:27 +01:00
|
|
|
dispatch(openPopover(POPOVER_USER_INFO, props))
|
2020-02-28 15:20:47 +00:00
|
|
|
},
|
|
|
|
closeUserInfoPopover() {
|
2020-04-24 04:17:27 +01:00
|
|
|
dispatch(closePopover(POPOVER_USER_INFO))
|
2020-02-28 15:20:47 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export default
|
|
|
|
@connect(null, mapDispatchToProps)
|
|
|
|
class DisplayName extends ImmutablePureComponent {
|
2020-02-08 06:12:01 +00:00
|
|
|
|
|
|
|
static propTypes = {
|
2020-03-24 04:39:12 +00:00
|
|
|
account: ImmutablePropTypes.map,
|
2020-02-28 15:20:47 +00:00
|
|
|
openUserInfoPopover: PropTypes.func.isRequired,
|
|
|
|
closeUserInfoPopover: PropTypes.func.isRequired,
|
2020-04-24 04:17:27 +01:00
|
|
|
isLarge: PropTypes.bool,
|
|
|
|
isMultiline: PropTypes.bool,
|
|
|
|
isSmall: PropTypes.bool,
|
2020-02-28 15:20:47 +00:00
|
|
|
noHover: PropTypes.bool,
|
2020-04-24 04:17:27 +01:00
|
|
|
noRelationship: PropTypes.bool,
|
2020-03-04 03:45:16 +00:00
|
|
|
noUsername: PropTypes.bool,
|
2020-05-07 00:40:54 +01:00
|
|
|
isComment: PropTypes.bool,
|
2020-05-10 04:26:58 +01:00
|
|
|
isCentered: PropTypes.bool,
|
2020-02-28 15:20:47 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 04:17:27 +01:00
|
|
|
updateOnProps = [
|
|
|
|
'account',
|
|
|
|
'isMultiline',
|
|
|
|
'isSmall',
|
|
|
|
'isLarge',
|
|
|
|
'noHover',
|
|
|
|
'noRelationship',
|
|
|
|
'noUsername',
|
2020-05-07 00:40:54 +01:00
|
|
|
'isComment',
|
2020-05-10 04:26:58 +01:00
|
|
|
'isCentered',
|
2020-04-24 04:17:27 +01:00
|
|
|
]
|
|
|
|
|
2020-04-23 07:13:29 +01:00
|
|
|
mouseOverTimeout = null
|
|
|
|
|
2020-06-13 02:51:39 +01:00
|
|
|
componentWillUnmount () {
|
|
|
|
document.removeEventListener('mousemove', this.handleMouseMove, true)
|
|
|
|
clearTimeout(this.mouseOverTimeout)
|
|
|
|
}
|
|
|
|
|
2020-04-23 07:13:29 +01:00
|
|
|
handleMouseEnter = () => {
|
|
|
|
if (this.mouseOverTimeout) return null
|
|
|
|
this.mouseOverTimeout = setTimeout(() => {
|
|
|
|
this.props.openUserInfoPopover({
|
|
|
|
targetRef: this.node,
|
|
|
|
position: 'top',
|
2020-06-13 02:51:39 +01:00
|
|
|
accountId: this.props.account.get('id'),
|
2020-04-23 07:13:29 +01:00
|
|
|
})
|
2020-06-13 02:51:39 +01:00
|
|
|
document.addEventListener('mousemove', this.handleMouseMove, true)
|
2020-04-23 07:13:29 +01:00
|
|
|
}, 650)
|
|
|
|
}
|
2020-03-11 23:56:18 +00:00
|
|
|
|
2020-06-13 02:51:39 +01:00
|
|
|
handleMouseLeave = debounce((e) => {
|
|
|
|
this.attemptToHidePopover(e)
|
|
|
|
}, 250)
|
|
|
|
|
|
|
|
handleMouseMove = debounce((e) => {
|
|
|
|
this.attemptToHidePopover(e)
|
|
|
|
}, 150)
|
|
|
|
|
|
|
|
attemptToHidePopover = (e) => {
|
|
|
|
const lastTarget = e.toElement || e.relatedTarget
|
|
|
|
if (!(lastTarget instanceof Element || lastTarget instanceof HTMLDocument)) return
|
|
|
|
|
|
|
|
const userInfoPopoverEl = document.getElementById('user-info-popover')
|
|
|
|
|
|
|
|
if (this.mouseOverTimeout &&
|
|
|
|
(
|
|
|
|
(userInfoPopoverEl && lastTarget && !userInfoPopoverEl.contains(lastTarget)) ||
|
|
|
|
(!userInfoPopoverEl && lastTarget && this.node && !this.node.contains(lastTarget))
|
|
|
|
)) {
|
|
|
|
document.removeEventListener('mousemove', this.handleMouseMove, true)
|
2020-04-23 07:13:29 +01:00
|
|
|
clearTimeout(this.mouseOverTimeout)
|
|
|
|
this.mouseOverTimeout = null
|
|
|
|
this.props.closeUserInfoPopover()
|
|
|
|
}
|
|
|
|
}
|
2020-02-28 15:20:47 +00:00
|
|
|
|
2020-03-11 23:56:18 +00:00
|
|
|
setRef = (n) => {
|
2020-04-23 07:13:29 +01:00
|
|
|
this.node = n
|
2020-02-21 00:57:29 +00:00
|
|
|
}
|
2020-02-08 06:12:01 +00:00
|
|
|
|
2020-02-28 15:20:47 +00:00
|
|
|
render() {
|
2020-03-04 03:45:16 +00:00
|
|
|
const {
|
|
|
|
account,
|
2020-04-24 04:17:27 +01:00
|
|
|
isMultiline,
|
|
|
|
isLarge,
|
2020-03-04 03:45:16 +00:00
|
|
|
noHover,
|
2020-03-08 23:02:28 +00:00
|
|
|
noUsername,
|
2020-04-24 04:17:27 +01:00
|
|
|
noRelationship,
|
2020-05-07 00:40:54 +01:00
|
|
|
isSmall,
|
|
|
|
isComment,
|
2020-05-10 04:26:58 +01:00
|
|
|
isCentered,
|
2020-03-04 03:45:16 +00:00
|
|
|
} = this.props
|
2020-02-28 15:20:47 +00:00
|
|
|
|
|
|
|
if (!account) return null
|
|
|
|
|
2020-04-24 04:17:27 +01:00
|
|
|
const containerClassName = CX({
|
|
|
|
default: 1,
|
|
|
|
maxWidth100PC: 1,
|
|
|
|
alignItemsCenter: !isMultiline,
|
|
|
|
flexRow: !isMultiline,
|
|
|
|
cursorPointer: !noHover,
|
2020-05-10 04:26:58 +01:00
|
|
|
alignItemsCenter: isCentered,
|
2020-04-24 04:17:27 +01:00
|
|
|
})
|
2020-02-28 15:20:47 +00:00
|
|
|
|
2020-04-24 04:17:27 +01:00
|
|
|
const displayNameClasses = CX({
|
2020-02-28 15:20:47 +00:00
|
|
|
text: 1,
|
|
|
|
overflowWrapBreakWord: 1,
|
|
|
|
whiteSpaceNoWrap: 1,
|
|
|
|
fontWeightBold: 1,
|
|
|
|
colorPrimary: 1,
|
2020-03-11 23:56:18 +00:00
|
|
|
mr2: 1,
|
2020-04-24 04:17:27 +01:00
|
|
|
lineHeight125: !isSmall,
|
2020-04-29 23:32:49 +01:00
|
|
|
fs14PX: isSmall,
|
|
|
|
fs15PX: !isLarge,
|
|
|
|
fs24PX: isLarge && !isSmall,
|
2020-02-28 15:20:47 +00:00
|
|
|
})
|
|
|
|
|
2020-04-24 04:17:27 +01:00
|
|
|
const usernameClasses = CX({
|
2020-02-28 15:20:47 +00:00
|
|
|
text: 1,
|
|
|
|
displayFlex: 1,
|
|
|
|
flexNormal: 1,
|
|
|
|
flexShrink1: 1,
|
|
|
|
overflowWrapBreakWord: 1,
|
|
|
|
textOverflowEllipsis: 1,
|
|
|
|
colorSecondary: 1,
|
|
|
|
fontWeightNormal: 1,
|
2020-04-24 04:17:27 +01:00
|
|
|
lineHeight15: isMultiline,
|
|
|
|
lineHeight125: !isMultiline,
|
|
|
|
ml5: !isMultiline,
|
2020-04-29 23:32:49 +01:00
|
|
|
fs14PX: isSmall,
|
|
|
|
fs15PX: !isLarge,
|
|
|
|
fs16PX: isLarge && !isSmall,
|
2020-02-28 15:20:47 +00:00
|
|
|
})
|
|
|
|
|
2020-03-08 23:02:28 +00:00
|
|
|
const iconSize =
|
2020-05-10 04:26:58 +01:00
|
|
|
!!isLarge ? 19 :
|
|
|
|
!!isComment ? 12 :
|
|
|
|
!!isSmall ? 14 : 15
|
2020-02-08 06:12:01 +00:00
|
|
|
|
2020-04-24 04:17:27 +01:00
|
|
|
let relationshipLabel
|
|
|
|
if (me && account) {
|
|
|
|
const accountId = account.get('id')
|
|
|
|
const isFollowedBy = (me !== accountId && account.getIn(['relationship', 'followed_by']))
|
|
|
|
|
|
|
|
if (isFollowedBy) {
|
|
|
|
relationshipLabel = 'Follows you'//intl.formatMessage(messages.accountFollowsYou)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// {
|
2020-06-13 02:51:39 +01:00
|
|
|
// /* : todo : audio-mute, bot
|
2020-04-24 04:17:27 +01:00
|
|
|
// account.getIn(['relationship', 'muting'])
|
|
|
|
// */
|
|
|
|
// }
|
2020-06-13 02:51:39 +01:00
|
|
|
// bot: { id: 'account.badges.bot', defaultMessage: 'Bot' },
|
2020-04-23 07:13:29 +01:00
|
|
|
|
2020-02-08 06:12:01 +00:00
|
|
|
return (
|
2020-04-24 04:17:27 +01:00
|
|
|
<div
|
|
|
|
className={containerClassName}
|
|
|
|
onMouseEnter={noHover ? undefined : this.handleMouseEnter}
|
|
|
|
onMouseLeave={noHover ? undefined : this.handleMouseLeave}
|
|
|
|
ref={this.setRef}
|
|
|
|
>
|
2020-05-10 04:26:58 +01:00
|
|
|
<span className={[_s.default, _s.flexRow, _s.alignItemsCenter, _s.maxWidth100PC].join(' ')}>
|
2020-02-28 15:20:47 +00:00
|
|
|
<bdi className={[_s.text, _s.whiteSpaceNoWrap, _s.textOverflowEllipsis].join(' ')}>
|
|
|
|
<strong
|
|
|
|
className={displayNameClasses}
|
|
|
|
dangerouslySetInnerHTML={{ __html: account.get('display_name_html') }}
|
|
|
|
/>
|
2020-04-24 04:17:27 +01:00
|
|
|
{
|
2020-05-10 04:26:58 +01:00
|
|
|
account.get('locked') &&
|
|
|
|
<Icon id='lock-filled' size={`${iconSize - 3}px`} className={[_s.fillPrimary, _s.ml5].join(' ')} />
|
2020-04-24 04:17:27 +01:00
|
|
|
}
|
2020-02-28 15:20:47 +00:00
|
|
|
</bdi>
|
|
|
|
{
|
|
|
|
account.get('is_verified') &&
|
2020-05-10 04:26:58 +01:00
|
|
|
<Icon id='verified' size={`${iconSize}px`} className={[_s.ml5, _s.default].join(' ')} />
|
2020-02-28 15:20:47 +00:00
|
|
|
}
|
2020-04-24 04:17:27 +01:00
|
|
|
</span>
|
2020-03-04 03:45:16 +00:00
|
|
|
{
|
|
|
|
!noUsername &&
|
|
|
|
<span className={usernameClasses}>
|
|
|
|
@{account.get('acct')}
|
2020-04-24 04:17:27 +01:00
|
|
|
{
|
|
|
|
!noRelationship && !!relationshipLabel &&
|
|
|
|
<span className={[_s.default, _s.ml5, _s.justifyContentCenter].join(' ')}>
|
|
|
|
<Text
|
|
|
|
size='extraSmall'
|
|
|
|
isBadge
|
|
|
|
color='tertiary'
|
2020-04-29 23:32:49 +01:00
|
|
|
className={[_s.bgSecondary, _s.py2].join(' ')}
|
2020-04-24 04:17:27 +01:00
|
|
|
>
|
|
|
|
{relationshipLabel}
|
|
|
|
</Text>
|
|
|
|
</span>
|
|
|
|
}
|
2020-03-04 03:45:16 +00:00
|
|
|
</span>
|
|
|
|
}
|
2020-04-24 04:17:27 +01:00
|
|
|
</div>
|
2020-02-21 00:57:29 +00:00
|
|
|
)
|
2020-02-08 06:12:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|