import React from 'react' import PropTypes from 'prop-types' import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePureComponent from 'react-immutable-pure-component' import { connect } from 'react-redux' import { openModal } from '../../actions/modal' import { showToast } from '../../actions/toasts' import { closePopover } from '../../actions/popover' import { TOAST_TYPE_SUCCESS } from '../../constants' import PopoverLayout from './popover_layout' import Button from '../button' import Heading from '../heading' import Text from '../text' import List from '../list' class SharePopover extends ImmutablePureComponent { state = { url: '', type: '', } componentDidMount() { this._setUrl() } componentDidUpdate() { this._setUrl() } _setUrl = () => { const { account, group, status } = this.props let url, type if (!!account) { type = 'account' url = account.get('url') } else if (!!group) { type = 'group' url = group.get('url') } else if (!!status) { type = 'status' url = status.get('url') } this.setState({ url, type }) } handleCopy = () => { const { url } = this.state const textarea = document.createElement('textarea') textarea.textContent = url textarea.style.position = 'fixed' document.body.appendChild(textarea) try { textarea.select() document.execCommand('copy') } catch (e) { // } document.body.removeChild(textarea) this.props.onShowCopyToast() this.handleClosePopover() } handleClosePopover = () => { this.props.onClosePopover() } render() { const { url, type } = this.state if (!url) return
const encodedUrl = encodeURIComponent(url) const mailToHref = `mailto:?subject=Gab&body=${encodedUrl}` const iconSize = '18px' return (