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.

87 lines
2.4 KiB

  1. import React from 'react';
  2. import Logo from 'mastodon/components/logo';
  3. import { Link, withRouter } from 'react-router-dom';
  4. import { FormattedMessage } from 'react-intl';
  5. import { registrationsOpen, me } from 'mastodon/initial_state';
  6. import Avatar from 'mastodon/components/avatar';
  7. import PropTypes from 'prop-types';
  8. import { connect } from 'react-redux';
  9. import { openModal } from 'mastodon/actions/modal';
  10. const Account = connect(state => ({
  11. account: state.getIn(['accounts', me]),
  12. }))(({ account }) => (
  13. <Link to={`/@${account.get('acct')}`} title={account.get('acct')}>
  14. <Avatar account={account} size={35} />
  15. </Link>
  16. ));
  17. const mapDispatchToProps = (dispatch) => ({
  18. openClosedRegistrationsModal() {
  19. dispatch(openModal('CLOSED_REGISTRATIONS'));
  20. },
  21. });
  22. export default @withRouter
  23. @connect(null, mapDispatchToProps)
  24. class Header extends React.PureComponent {
  25. static contextTypes = {
  26. identity: PropTypes.object,
  27. };
  28. static propTypes = {
  29. openClosedRegistrationsModal: PropTypes.func,
  30. location: PropTypes.object,
  31. };
  32. render () {
  33. const { signedIn } = this.context.identity;
  34. const { location, openClosedRegistrationsModal } = this.props;
  35. let content;
  36. if (signedIn) {
  37. content = (
  38. <>
  39. {location.pathname !== '/publish' && <Link to='/publish' className='button'><FormattedMessage id='compose_form.publish_form' defaultMessage='Publish' /></Link>}
  40. <Account />
  41. </>
  42. );
  43. } else {
  44. let signupButton;
  45. if (registrationsOpen) {
  46. signupButton = (
  47. <a href='/auth/sign_up' className='button button-tertiary'>
  48. <FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' />
  49. </a>
  50. );
  51. } else {
  52. signupButton = (
  53. <button className='button button-tertiary' onClick={openClosedRegistrationsModal}>
  54. <FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' />
  55. </button>
  56. );
  57. }
  58. content = (
  59. <>
  60. <a href='/auth/sign_in' className='button'><FormattedMessage id='sign_in_banner.sign_in' defaultMessage='Sign in' /></a>
  61. {signupButton}
  62. </>
  63. );
  64. }
  65. return (
  66. <div className='ui__header'>
  67. <Link to='/' className='ui__header__logo'><Logo /></Link>
  68. <div className='ui__header__links'>
  69. {content}
  70. </div>
  71. </div>
  72. );
  73. }
  74. }