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.

162 lines
6.0 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { FormattedMessage } from 'react-intl';
  4. import { registrationsOpen } from 'mastodon/initial_state';
  5. import { connect } from 'react-redux';
  6. import Icon from 'mastodon/components/icon';
  7. import classNames from 'classnames';
  8. import { openModal, closeModal } from 'mastodon/actions/modal';
  9. const mapStateToProps = (state, { accountId }) => ({
  10. displayNameHtml: state.getIn(['accounts', accountId, 'display_name_html']),
  11. });
  12. const mapDispatchToProps = (dispatch) => ({
  13. onSignupClick() {
  14. dispatch(closeModal());
  15. dispatch(openModal('CLOSED_REGISTRATIONS'));
  16. },
  17. });
  18. class Copypaste extends React.PureComponent {
  19. static propTypes = {
  20. value: PropTypes.string,
  21. };
  22. state = {
  23. copied: false,
  24. };
  25. setRef = c => {
  26. this.input = c;
  27. };
  28. handleInputClick = () => {
  29. this.setState({ copied: false });
  30. this.input.focus();
  31. this.input.select();
  32. this.input.setSelectionRange(0, this.input.value.length);
  33. };
  34. handleButtonClick = () => {
  35. const { value } = this.props;
  36. navigator.clipboard.writeText(value);
  37. this.input.blur();
  38. this.setState({ copied: true });
  39. this.timeout = setTimeout(() => this.setState({ copied: false }), 700);
  40. };
  41. componentWillUnmount () {
  42. if (this.timeout) clearTimeout(this.timeout);
  43. }
  44. render () {
  45. const { value } = this.props;
  46. const { copied } = this.state;
  47. return (
  48. <div className={classNames('copypaste', { copied })}>
  49. <input
  50. type='text'
  51. ref={this.setRef}
  52. value={value}
  53. readOnly
  54. onClick={this.handleInputClick}
  55. />
  56. <button className='button' onClick={this.handleButtonClick}>
  57. {copied ? <FormattedMessage id='copypaste.copied' defaultMessage='Copied' /> : <FormattedMessage id='copypaste.copy' defaultMessage='Copy' />}
  58. </button>
  59. </div>
  60. );
  61. }
  62. }
  63. class InteractionModal extends React.PureComponent {
  64. static propTypes = {
  65. displayNameHtml: PropTypes.string,
  66. url: PropTypes.string,
  67. type: PropTypes.oneOf(['reply', 'reblog', 'favourite', 'follow']),
  68. onSignupClick: PropTypes.func.isRequired,
  69. };
  70. handleSignupClick = () => {
  71. this.props.onSignupClick();
  72. };
  73. render () {
  74. const { url, type, displayNameHtml } = this.props;
  75. const name = <bdi dangerouslySetInnerHTML={{ __html: displayNameHtml }} />;
  76. let title, actionDescription, icon;
  77. switch(type) {
  78. case 'reply':
  79. icon = <Icon id='reply' />;
  80. title = <FormattedMessage id='interaction_modal.title.reply' defaultMessage="Reply to {name}'s post" values={{ name }} />;
  81. actionDescription = <FormattedMessage id='interaction_modal.description.reply' defaultMessage='With an account on Mastodon, you can respond to this post.' />;
  82. break;
  83. case 'reblog':
  84. icon = <Icon id='retweet' />;
  85. title = <FormattedMessage id='interaction_modal.title.reblog' defaultMessage="Boost {name}'s post" values={{ name }} />;
  86. actionDescription = <FormattedMessage id='interaction_modal.description.reblog' defaultMessage='With an account on Mastodon, you can boost this post to share it with your own followers.' />;
  87. break;
  88. case 'favourite':
  89. icon = <Icon id='star' />;
  90. title = <FormattedMessage id='interaction_modal.title.favourite' defaultMessage="Favourite {name}'s post" values={{ name }} />;
  91. actionDescription = <FormattedMessage id='interaction_modal.description.favourite' defaultMessage='With an account on Mastodon, you can favourite this post to let the author know you appreciate it and save it for later.' />;
  92. break;
  93. case 'follow':
  94. icon = <Icon id='user-plus' />;
  95. title = <FormattedMessage id='interaction_modal.title.follow' defaultMessage='Follow {name}' values={{ name }} />;
  96. actionDescription = <FormattedMessage id='interaction_modal.description.follow' defaultMessage='With an account on Mastodon, you can follow {name} to receive their posts in your home feed.' values={{ name }} />;
  97. break;
  98. }
  99. let signupButton;
  100. if (registrationsOpen) {
  101. signupButton = (
  102. <a href='/auth/sign_up' className='button button--block button-tertiary'>
  103. <FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' />
  104. </a>
  105. );
  106. } else {
  107. signupButton = (
  108. <button className='button button--block button-tertiary' onClick={this.handleSignupClick}>
  109. <FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' />
  110. </button>
  111. );
  112. }
  113. return (
  114. <div className='modal-root__modal interaction-modal'>
  115. <div className='interaction-modal__lead'>
  116. <h3><span className='interaction-modal__icon'>{icon}</span> {title}</h3>
  117. <p>{actionDescription} <FormattedMessage id='interaction_modal.preamble' defaultMessage="Since Mastodon is decentralized, you can use your existing account hosted by another Mastodon server or compatible platform if you don't have an account on this one." /></p>
  118. </div>
  119. <div className='interaction-modal__choices'>
  120. <div className='interaction-modal__choices__choice'>
  121. <h3><FormattedMessage id='interaction_modal.on_this_server' defaultMessage='On this server' /></h3>
  122. <a href='/auth/sign_in' className='button button--block'><FormattedMessage id='sign_in_banner.sign_in' defaultMessage='Sign in' /></a>
  123. {signupButton}
  124. </div>
  125. <div className='interaction-modal__choices__choice'>
  126. <h3><FormattedMessage id='interaction_modal.on_another_server' defaultMessage='On a different server' /></h3>
  127. <p><FormattedMessage id='interaction_modal.other_server_instructions' defaultMessage='Copy and paste this URL into the search field of your favourite Mastodon app or the web interface of your Mastodon server.' /></p>
  128. <Copypaste value={url} />
  129. </div>
  130. </div>
  131. </div>
  132. );
  133. }
  134. }
  135. export default connect(mapStateToProps, mapDispatchToProps)(InteractionModal);