import { PureComponent } from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import { registrationsOpen } from 'flavours/glitch/initial_state'; import { connect } from 'react-redux'; import { Icon } from 'flavours/glitch/components/icon'; import classNames from 'classnames'; import { openModal, closeModal } from 'flavours/glitch/actions/modal'; const mapStateToProps = (state, { accountId }) => ({ displayNameHtml: state.getIn(['accounts', accountId, 'display_name_html']), signupUrl: state.getIn(['server', 'server', 'registrations', 'url'], '/auth/sign_up'), }); const mapDispatchToProps = (dispatch) => ({ onSignupClick() { dispatch(closeModal()); dispatch(openModal('CLOSED_REGISTRATIONS')); }, }); class Copypaste extends PureComponent { static propTypes = { value: PropTypes.string, }; state = { copied: false, }; setRef = c => { this.input = c; }; handleInputClick = () => { this.setState({ copied: false }); this.input.focus(); this.input.select(); this.input.setSelectionRange(0, this.input.value.length); }; handleButtonClick = () => { const { value } = this.props; navigator.clipboard.writeText(value); this.input.blur(); this.setState({ copied: true }); this.timeout = setTimeout(() => this.setState({ copied: false }), 700); }; componentWillUnmount () { if (this.timeout) clearTimeout(this.timeout); } render () { const { value } = this.props; const { copied } = this.state; return (
); } } class InteractionModal extends PureComponent { static propTypes = { displayNameHtml: PropTypes.string, url: PropTypes.string, type: PropTypes.oneOf(['reply', 'reblog', 'favourite', 'follow']), onSignupClick: PropTypes.func.isRequired, signupUrl: PropTypes.string.isRequired, }; handleSignupClick = () => { this.props.onSignupClick(); }; render () { const { url, type, displayNameHtml, signupUrl } = this.props; const name = ; let title, actionDescription, icon; switch(type) { case 'reply': icon = ; title = ; actionDescription = ; break; case 'reblog': icon = ; title = ; actionDescription = ; break; case 'favourite': icon = ; title = ; actionDescription = ; break; case 'follow': icon = ; title = ; actionDescription = ; break; } let signupButton; if (registrationsOpen) { signupButton = ( ); } else { signupButton = ( ); } return (

{icon} {title}

{actionDescription}

{signupButton}

); } } export default connect(mapStateToProps, mapDispatchToProps)(InteractionModal);