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.
113 lines
4.1 KiB
113 lines
4.1 KiB
7 years ago
|
// Package imports //
|
||
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
8 years ago
|
import escapeTextContentForBrowser from 'escape-html';
|
||
8 years ago
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
||
8 years ago
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||
7 years ago
|
|
||
|
// Mastodon imports //
|
||
|
import emojify from '../../../mastodon/emoji';
|
||
|
import IconButton from '../../../mastodon/components/icon_button';
|
||
|
import Avatar from '../../../mastodon/components/avatar';
|
||
|
|
||
|
// Our imports //
|
||
|
import { processBio } from '../../util/bio_metadata';
|
||
8 years ago
|
|
||
|
const messages = defineMessages({
|
||
|
unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
|
||
|
follow: { id: 'account.follow', defaultMessage: 'Follow' },
|
||
8 years ago
|
requested: { id: 'account.requested', defaultMessage: 'Awaiting approval' },
|
||
8 years ago
|
});
|
||
8 years ago
|
|
||
8 years ago
|
@injectIntl
|
||
|
export default class Header extends ImmutablePureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
static propTypes = {
|
||
|
account: ImmutablePropTypes.map,
|
||
|
me: PropTypes.number.isRequired,
|
||
|
onFollow: PropTypes.func.isRequired,
|
||
|
intl: PropTypes.object.isRequired,
|
||
|
};
|
||
|
|
||
8 years ago
|
render () {
|
||
8 years ago
|
const { account, me, intl } = this.props;
|
||
8 years ago
|
|
||
8 years ago
|
if (!account) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
8 years ago
|
let displayName = account.get('display_name');
|
||
8 years ago
|
let info = '';
|
||
8 years ago
|
let actionBtn = '';
|
||
8 years ago
|
let lockedIcon = '';
|
||
8 years ago
|
|
||
|
if (displayName.length === 0) {
|
||
|
displayName = account.get('username');
|
||
|
}
|
||
|
|
||
8 years ago
|
if (me !== account.get('id') && account.getIn(['relationship', 'followed_by'])) {
|
||
8 years ago
|
info = <span className='account--follows-info'><FormattedMessage id='account.follows_you' defaultMessage='Follows you' /></span>;
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
if (me !== account.get('id')) {
|
||
8 years ago
|
if (account.getIn(['relationship', 'requested'])) {
|
||
|
actionBtn = (
|
||
8 years ago
|
<div className='account--action-button'>
|
||
8 years ago
|
<IconButton size={26} disabled icon='hourglass' title={intl.formatMessage(messages.requested)} />
|
||
8 years ago
|
</div>
|
||
|
);
|
||
8 years ago
|
} else if (!account.getIn(['relationship', 'blocking'])) {
|
||
8 years ago
|
actionBtn = (
|
||
8 years ago
|
<div className='account--action-button'>
|
||
8 years ago
|
<IconButton size={26} icon={account.getIn(['relationship', 'following']) ? 'user-times' : 'user-plus'} active={account.getIn(['relationship', 'following'])} title={intl.formatMessage(account.getIn(['relationship', 'following']) ? messages.unfollow : messages.follow)} onClick={this.props.onFollow} />
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
if (account.get('locked')) {
|
||
|
lockedIcon = <i className='fa fa-lock' />;
|
||
|
}
|
||
|
|
||
8 years ago
|
const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
|
||
|
const { text, metadata } = processBio(account.get('note'));
|
||
8 years ago
|
|
||
8 years ago
|
return (
|
||
8 years ago
|
<div className='account__header__wrapper'>
|
||
|
<div className='account__header' style={{ backgroundImage: `url(${account.get('header')})` }}>
|
||
|
<div>
|
||
8 years ago
|
<a href={account.get('url')} target='_blank' rel='noopener'>
|
||
7 years ago
|
<span className='account__header__avatar'><Avatar src={account.get('avatar')} staticSrc={account.get('avatar_static')} size={90} /></span>
|
||
8 years ago
|
<span className='account__header__display-name' dangerouslySetInnerHTML={displayNameHTML} />
|
||
|
</a>
|
||
8 years ago
|
<span className='account__header__username'>@{account.get('acct')} {lockedIcon}</span>
|
||
8 years ago
|
<div className='account__header__content' dangerouslySetInnerHTML={{ __html: emojify(text) }} />
|
||
8 years ago
|
|
||
8 years ago
|
{info}
|
||
|
{actionBtn}
|
||
|
</div>
|
||
8 years ago
|
</div>
|
||
8 years ago
|
|
||
|
{metadata.length && (
|
||
8 years ago
|
<table className='account__metadata'>
|
||
8 years ago
|
{(() => {
|
||
|
let data = [];
|
||
|
for (let i = 0; i < metadata.length; i++) {
|
||
|
data.push(
|
||
8 years ago
|
<tr key={i}>
|
||
|
<th scope='row'><div dangerouslySetInnerHTML={{ __html: emojify(metadata[i][0]) }} /></th>
|
||
|
<td><div dangerouslySetInnerHTML={{ __html: emojify(metadata[i][1]) }} /></td>
|
||
|
</tr>
|
||
8 years ago
|
);
|
||
|
}
|
||
|
return data;
|
||
|
})()}
|
||
8 years ago
|
</table>
|
||
8 years ago
|
) || null}
|
||
8 years ago
|
</div>
|
||
|
);
|
||
|
}
|
||
|
|
||
8 years ago
|
}
|