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