index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. export default @connect(mapStateToProps, mapDispatchToProps)
  64. class InteractionModal extends React.PureComponent {
  65. static propTypes = {
  66. displayNameHtml: PropTypes.string,
  67. url: PropTypes.string,
  68. type: PropTypes.oneOf(['reply', 'reblog', 'favourite', 'follow']),
  69. onSignupClick: PropTypes.func.isRequired,
  70. };
  71. handleSignupClick = () => {
  72. this.props.onSignupClick();
  73. }
  74. render () {
  75. const { url, type, displayNameHtml } = this.props;
  76. const name = <bdi dangerouslySetInnerHTML={{ __html: displayNameHtml }} />;
  77. let title, actionDescription, icon;
  78. switch(type) {
  79. case 'reply':
  80. icon = <Icon id='reply' />;
  81. title = <FormattedMessage id='interaction_modal.title.reply' defaultMessage="Reply to {name}'s post" values={{ name }} />;
  82. actionDescription = <FormattedMessage id='interaction_modal.description.reply' defaultMessage='With an account on Mastodon, you can respond to this post.' />;
  83. break;
  84. case 'reblog':
  85. icon = <Icon id='retweet' />;
  86. title = <FormattedMessage id='interaction_modal.title.reblog' defaultMessage="Boost {name}'s post" values={{ name }} />;
  87. 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.' />;
  88. break;
  89. case 'favourite':
  90. icon = <Icon id='star' />;
  91. title = <FormattedMessage id='interaction_modal.title.favourite' defaultMessage="Favourite {name}'s post" values={{ name }} />;
  92. 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.' />;
  93. break;
  94. case 'follow':
  95. icon = <Icon id='user-plus' />;
  96. title = <FormattedMessage id='interaction_modal.title.follow' defaultMessage='Follow {name}' values={{ name }} />;
  97. 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 }} />;
  98. break;
  99. }
  100. let signupButton;
  101. if (registrationsOpen) {
  102. signupButton = (
  103. <a href='/auth/sign_up' className='button button--block button-tertiary'>
  104. <FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' />
  105. </a>
  106. );
  107. } else {
  108. signupButton = (
  109. <button className='button button--block button-tertiary' onClick={this.handleSignupClick}>
  110. <FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' />
  111. </button>
  112. );
  113. }
  114. return (
  115. <div className='modal-root__modal interaction-modal'>
  116. <div className='interaction-modal__lead'>
  117. <h3><span className='interaction-modal__icon'>{icon}</span> {title}</h3>
  118. <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>
  119. </div>
  120. <div className='interaction-modal__choices'>
  121. <div className='interaction-modal__choices__choice'>
  122. <h3><FormattedMessage id='interaction_modal.on_this_server' defaultMessage='On this server' /></h3>
  123. <a href='/auth/sign_in' className='button button--block'><FormattedMessage id='sign_in_banner.sign_in' defaultMessage='Sign in' /></a>
  124. {signupButton}
  125. </div>
  126. <div className='interaction-modal__choices__choice'>
  127. <h3><FormattedMessage id='interaction_modal.on_another_server' defaultMessage='On a different server' /></h3>
  128. <p><FormattedMessage id='interaction_modal.other_server_instructions' defaultMessage='Simply copy and paste this URL into the search bar of your favourite app or the web interface where you are signed in.' /></p>
  129. <Copypaste value={url} />
  130. </div>
  131. </div>
  132. </div>
  133. );
  134. }
  135. }