2022-10-04 18:13:23 +00:00
|
|
|
import React from 'react';
|
|
|
|
import Logo from 'flavours/glitch/components/logo';
|
2022-10-23 13:58:24 +00:00
|
|
|
import { Link, withRouter } from 'react-router-dom';
|
2022-10-04 18:13:23 +00:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
import { registrationsOpen, me } from 'flavours/glitch/initial_state';
|
|
|
|
import Avatar from 'flavours/glitch/components/avatar';
|
|
|
|
import Permalink from 'flavours/glitch/components/permalink';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
2022-12-06 23:25:40 +00:00
|
|
|
import { openModal } from 'flavours/glitch/actions/modal';
|
2022-10-04 18:13:23 +00:00
|
|
|
|
|
|
|
const Account = connect(state => ({
|
|
|
|
account: state.getIn(['accounts', me]),
|
|
|
|
}))(({ account }) => (
|
2022-10-09 13:55:32 +00:00
|
|
|
<Permalink href={account.get('url')} to={`/@${account.get('acct')}`} title={account.get('acct')}>
|
2022-10-04 18:13:23 +00:00
|
|
|
<Avatar account={account} size={35} />
|
|
|
|
</Permalink>
|
|
|
|
));
|
|
|
|
|
2022-12-06 23:25:40 +00:00
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
openClosedRegistrationsModal() {
|
|
|
|
dispatch(openModal('CLOSED_REGISTRATIONS'));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-10-23 13:58:24 +00:00
|
|
|
class Header extends React.PureComponent {
|
2022-10-04 18:13:23 +00:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
identity: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
2022-10-23 13:58:24 +00:00
|
|
|
static propTypes = {
|
2022-12-06 23:25:40 +00:00
|
|
|
openClosedRegistrationsModal: PropTypes.func,
|
2022-10-23 13:58:24 +00:00
|
|
|
location: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
2022-10-04 18:13:23 +00:00
|
|
|
render () {
|
|
|
|
const { signedIn } = this.context.identity;
|
2022-12-06 23:25:40 +00:00
|
|
|
const { location, openClosedRegistrationsModal } = this.props;
|
2022-10-04 18:13:23 +00:00
|
|
|
|
|
|
|
let content;
|
|
|
|
|
|
|
|
if (signedIn) {
|
2022-10-23 13:58:24 +00:00
|
|
|
content = (
|
|
|
|
<>
|
2022-11-17 09:53:38 +00:00
|
|
|
{location.pathname !== '/publish' && <Link to='/publish' className='button'><FormattedMessage id='compose_form.publish_form' defaultMessage='Publish' /></Link>}
|
2022-10-23 13:58:24 +00:00
|
|
|
<Account />
|
|
|
|
</>
|
|
|
|
);
|
2022-10-04 18:13:23 +00:00
|
|
|
} else {
|
2022-12-06 23:25:40 +00:00
|
|
|
let signupButton;
|
|
|
|
|
|
|
|
if (registrationsOpen) {
|
|
|
|
signupButton = (
|
|
|
|
<a href='/auth/sign_up' className='button button-tertiary'>
|
|
|
|
<FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' />
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
signupButton = (
|
|
|
|
<button className='button button-tertiary' onClick={openClosedRegistrationsModal}>
|
|
|
|
<FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' />
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-04 18:13:23 +00:00
|
|
|
content = (
|
2022-10-23 13:58:24 +00:00
|
|
|
<>
|
2022-10-04 18:13:23 +00:00
|
|
|
<a href='/auth/sign_in' className='button'><FormattedMessage id='sign_in_banner.sign_in' defaultMessage='Sign in' /></a>
|
2022-12-06 23:25:40 +00:00
|
|
|
{signupButton}
|
2022-10-23 13:58:24 +00:00
|
|
|
</>
|
2022-10-04 18:13:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='ui__header'>
|
|
|
|
<Link to='/' className='ui__header__logo'><Logo /></Link>
|
|
|
|
|
|
|
|
<div className='ui__header__links'>
|
|
|
|
{content}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-24 22:15:25 +00:00
|
|
|
|
|
|
|
export default withRouter(connect(null, mapDispatchToProps)(Header));
|