gab-social/app/javascript/gabsocial/components/popover/status_share_popover.js

101 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-03-25 03:08:43 +00:00
import ImmutablePropTypes from 'react-immutable-proptypes'
import ImmutablePureComponent from 'react-immutable-pure-component'
import { defineMessages, injectIntl } from 'react-intl'
2020-05-01 06:50:27 +01:00
import { closePopover } from '../../actions/popover'
import { openModal } from '../../actions/modal'
import {
MODAL_EMBED,
POPOVER_STATUS_SHARE,
} from '../../constants'
2020-03-25 03:08:43 +00:00
import PopoverLayout from './popover_layout'
import List from '../list'
const messages = defineMessages({
2020-05-01 06:50:27 +01:00
embed: { id: 'status.embed', defaultMessage: 'Embed' },
email: { id: 'status.email', defaultMessage: 'Email this gab' },
copy: { id: 'status.copy', defaultMessage: 'Copy link to status' },
2020-03-25 03:08:43 +00:00
});
2020-05-01 06:50:27 +01:00
const mapDispatchToProps = (dispatch) => ({
onClosePopover: () => dispatch(closePopover(POPOVER_STATUS_SHARE)),
onOpenEmbedModal(url) {
dispatch(openModal(MODAL_EMBED, {
url,
}))
},
});
2020-04-07 02:53:23 +01:00
2020-03-25 03:08:43 +00:00
export default
@injectIntl
2020-05-01 06:50:27 +01:00
@connect(null, mapDispatchToProps)
2020-03-25 03:08:43 +00:00
class StatusSharePopover extends ImmutablePureComponent {
2020-05-01 06:50:27 +01:00
2020-03-25 03:08:43 +00:00
static propTypes = {
status: ImmutablePropTypes.map,
intl: PropTypes.object.isRequired,
2020-05-01 06:50:27 +01:00
onClosePopover: PropTypes.func.isRequired,
onOpenEmbedModal: PropTypes.func.isRequired,
isXS: PropTypes.bool,
2020-03-25 03:08:43 +00:00
}
2020-05-01 06:50:27 +01:00
handleOnOpenEmbedModal = () => {
this.props.onOpenEmbedModal(this.props.status.get('url'))
this.props.onClosePopover()
2020-03-25 03:08:43 +00:00
}
handleCopy = () => {
2020-05-01 06:50:27 +01:00
const url = this.props.status.get('url');
const textarea = document.createElement('textarea');
2020-03-25 03:08:43 +00:00
2020-05-01 06:50:27 +01:00
textarea.textContent = url;
textarea.style.position = 'fixed';
2020-03-25 03:08:43 +00:00
2020-05-01 06:50:27 +01:00
document.body.appendChild(textarea);
2020-03-25 03:08:43 +00:00
2020-05-01 06:50:27 +01:00
try {
textarea.select();
document.execCommand('copy');
} catch (e) {
//
}
document.body.removeChild(textarea);
this.props.onClosePopover()
2020-03-25 03:08:43 +00:00
}
render() {
const { intl, status, isXS } = this.props
2020-05-01 06:50:27 +01:00
2020-05-10 04:26:58 +01:00
const mailToHref = !status ? undefined : `mailto:?subject=Gab&body=${status.get('url')}`
2020-03-25 03:08:43 +00:00
return (
<PopoverLayout width={220} isXS={isXS}>
2020-03-25 03:08:43 +00:00
<List
2020-04-07 02:53:23 +01:00
size='large'
2020-03-25 03:08:43 +00:00
scrollKey='status_share_options'
items={[
{
icon: 'copy',
hideArrow: true,
title: intl.formatMessage(messages.copy),
onClick: this.handleCopy,
},
{
2020-04-07 02:53:23 +01:00
icon: 'email',
2020-03-25 03:08:43 +00:00
hideArrow: true,
title: intl.formatMessage(messages.email),
2020-05-01 06:50:27 +01:00
href: mailToHref,
2020-03-25 03:08:43 +00:00
},
{
2020-04-07 02:53:23 +01:00
icon: 'code',
2020-03-25 03:08:43 +00:00
hideArrow: true,
title: intl.formatMessage(messages.embed),
2020-05-01 06:50:27 +01:00
onClick: this.handleOnOpenEmbedModal,
2020-03-25 03:08:43 +00:00
},
]}
small
/>
</PopoverLayout>
)
}
}