You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.0 KiB
103 lines
3.0 KiB
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||
5 years ago
|
import PropTypes from 'prop-types';
|
||
|
import classNames from 'classnames';
|
||
2 years ago
|
import { autoPlayGif } from 'flavours/glitch/initial_state';
|
||
2 years ago
|
import Skeleton from 'flavours/glitch/components/skeleton';
|
||
8 years ago
|
|
||
5 years ago
|
export default class DisplayName extends React.PureComponent {
|
||
8 years ago
|
|
||
5 years ago
|
static propTypes = {
|
||
|
account: ImmutablePropTypes.map,
|
||
|
className: PropTypes.string,
|
||
|
inline: PropTypes.bool,
|
||
|
localDomain: PropTypes.string,
|
||
|
others: ImmutablePropTypes.list,
|
||
|
handleClick: PropTypes.func,
|
||
|
};
|
||
6 years ago
|
|
||
4 years ago
|
handleMouseEnter = ({ currentTarget }) => {
|
||
|
if (autoPlayGif) {
|
||
5 years ago
|
return;
|
||
|
}
|
||
|
|
||
4 years ago
|
const emojis = currentTarget.querySelectorAll('.custom-emoji');
|
||
5 years ago
|
|
||
|
for (var i = 0; i < emojis.length; i++) {
|
||
|
let emoji = emojis[i];
|
||
4 years ago
|
emoji.src = emoji.getAttribute('data-original');
|
||
5 years ago
|
}
|
||
2 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
handleMouseLeave = ({ currentTarget }) => {
|
||
|
if (autoPlayGif) {
|
||
|
return;
|
||
|
}
|
||
5 years ago
|
|
||
4 years ago
|
const emojis = currentTarget.querySelectorAll('.custom-emoji');
|
||
5 years ago
|
|
||
4 years ago
|
for (var i = 0; i < emojis.length; i++) {
|
||
|
let emoji = emojis[i];
|
||
|
emoji.src = emoji.getAttribute('data-static');
|
||
|
}
|
||
2 years ago
|
};
|
||
5 years ago
|
|
||
5 years ago
|
render() {
|
||
|
const { account, className, inline, localDomain, others, onAccountClick } = this.props;
|
||
6 years ago
|
|
||
5 years ago
|
const computedClass = classNames('display-name', { inline }, className);
|
||
6 years ago
|
|
||
5 years ago
|
let displayName, suffix;
|
||
2 years ago
|
let acct;
|
||
6 years ago
|
|
||
2 years ago
|
if (account) {
|
||
|
acct = account.get('acct');
|
||
6 years ago
|
|
||
2 years ago
|
if (acct.indexOf('@') === -1 && localDomain) {
|
||
|
acct = `${acct}@${localDomain}`;
|
||
|
}
|
||
6 years ago
|
}
|
||
|
|
||
5 years ago
|
if (others && others.size > 0) {
|
||
|
displayName = others.take(2).map(a => (
|
||
|
<a
|
||
|
href={a.get('url')}
|
||
|
target='_blank'
|
||
3 years ago
|
onClick={(e) => onAccountClick(a.get('acct'), e)}
|
||
5 years ago
|
title={`@${a.get('acct')}`}
|
||
5 years ago
|
rel='noopener noreferrer'
|
||
5 years ago
|
>
|
||
|
<bdi key={a.get('id')}>
|
||
|
<strong className='display-name__html' dangerouslySetInnerHTML={{ __html: a.get('display_name_html') }} />
|
||
|
</bdi>
|
||
|
</a>
|
||
|
)).reduce((prev, cur) => [prev, ', ', cur]);
|
||
|
|
||
|
if (others.size - 2 > 0) {
|
||
2 years ago
|
displayName.push(` +${others.size - 2}`);
|
||
5 years ago
|
}
|
||
|
|
||
|
suffix = (
|
||
3 years ago
|
<a href={account.get('url')} target='_blank' onClick={(e) => onAccountClick(account.get('acct'), e)} rel='noopener noreferrer'>
|
||
5 years ago
|
<span className='display-name__account'>@{acct}</span>
|
||
|
</a>
|
||
|
);
|
||
2 years ago
|
} else if (account) {
|
||
5 years ago
|
displayName = <bdi><strong className='display-name__html' dangerouslySetInnerHTML={{ __html: account.get('display_name_html') }} /></bdi>;
|
||
|
suffix = <span className='display-name__account'>@{acct}</span>;
|
||
2 years ago
|
} else {
|
||
|
displayName = <bdi><strong className='display-name__html'><Skeleton width='10ch' /></strong></bdi>;
|
||
|
suffix = <span className='display-name__account'><Skeleton width='7ch' /></span>;
|
||
5 years ago
|
}
|
||
|
|
||
|
return (
|
||
4 years ago
|
<span className={computedClass} onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>
|
||
5 years ago
|
{displayName}
|
||
|
{inline ? ' ' : null}
|
||
|
{suffix}
|
||
|
</span>
|
||
6 years ago
|
);
|
||
|
}
|
||
|
|
||
8 years ago
|
}
|