2022-10-04 20:13:23 +02:00
|
|
|
import React from 'react';
|
|
|
|
import Logo from 'mastodon/components/logo';
|
2022-10-23 15:58:24 +02:00
|
|
|
import { Link, withRouter } from 'react-router-dom';
|
2022-10-04 20:13:23 +02:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
import { registrationsOpen, me } from 'mastodon/initial_state';
|
|
|
|
import Avatar from 'mastodon/components/avatar';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
const Account = connect(state => ({
|
|
|
|
account: state.getIn(['accounts', me]),
|
|
|
|
}))(({ account }) => (
|
2022-11-13 21:10:20 +01:00
|
|
|
<Link to={`/@${account.get('acct')}`} title={account.get('acct')}>
|
2022-10-04 20:13:23 +02:00
|
|
|
<Avatar account={account} size={35} />
|
2022-11-13 21:10:20 +01:00
|
|
|
</Link>
|
2022-10-04 20:13:23 +02:00
|
|
|
));
|
|
|
|
|
2022-10-23 15:58:24 +02:00
|
|
|
export default @withRouter
|
|
|
|
class Header extends React.PureComponent {
|
2022-10-04 20:13:23 +02:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
identity: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
2022-10-23 15:58:24 +02:00
|
|
|
static propTypes = {
|
|
|
|
location: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
2022-10-04 20:13:23 +02:00
|
|
|
render () {
|
|
|
|
const { signedIn } = this.context.identity;
|
2022-10-23 15:58:24 +02:00
|
|
|
const { location } = this.props;
|
2022-10-04 20:13:23 +02:00
|
|
|
|
|
|
|
let content;
|
|
|
|
|
|
|
|
if (signedIn) {
|
2022-10-23 15:58:24 +02:00
|
|
|
content = (
|
|
|
|
<>
|
|
|
|
{location.pathname !== '/publish' && <Link to='/publish' className='button'><FormattedMessage id='compose_form.publish' defaultMessage='Publish' /></Link>}
|
|
|
|
<Account />
|
|
|
|
</>
|
|
|
|
);
|
2022-10-04 20:13:23 +02:00
|
|
|
} else {
|
|
|
|
content = (
|
2022-10-23 15:58:24 +02:00
|
|
|
<>
|
2022-10-04 20:13:23 +02:00
|
|
|
<a href='/auth/sign_in' className='button'><FormattedMessage id='sign_in_banner.sign_in' defaultMessage='Sign in' /></a>
|
|
|
|
<a href={registrationsOpen ? '/auth/sign_up' : 'https://joinmastodon.org/servers'} className='button button-tertiary'><FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' /></a>
|
2022-10-23 15:58:24 +02:00
|
|
|
</>
|
2022-10-04 20:13:23 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='ui__header'>
|
|
|
|
<Link to='/' className='ui__header__logo'><Logo /></Link>
|
|
|
|
|
|
|
|
<div className='ui__header__links'>
|
|
|
|
{content}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|