2020-10-24 20:17:21 +01:00
|
|
|
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'
|
2020-12-16 00:31:30 +00:00
|
|
|
import { showToast } from '../../actions/toasts'
|
2020-10-24 20:17:21 +01:00
|
|
|
import { closePopover } from '../../actions/popover'
|
2020-12-24 18:27:55 +00:00
|
|
|
import { TOAST_TYPE_SUCCESS } from '../../constants'
|
2020-10-24 20:17:21 +01:00
|
|
|
import PopoverLayout from './popover_layout'
|
2020-10-25 00:50:09 +01:00
|
|
|
import Button from '../button'
|
|
|
|
import Heading from '../heading'
|
|
|
|
import Text from '../text'
|
2020-10-24 20:17:21 +01:00
|
|
|
import List from '../list'
|
|
|
|
|
2020-12-24 18:27:55 +00:00
|
|
|
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 })
|
|
|
|
}
|
2020-10-24 20:17:21 +01:00
|
|
|
|
|
|
|
handleCopy = () => {
|
2020-12-24 18:27:55 +00:00
|
|
|
const { url } = this.state
|
2020-10-24 20:17:21 +01:00
|
|
|
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)
|
2020-12-16 00:31:30 +00:00
|
|
|
this.props.onShowCopyToast()
|
2020-10-24 20:17:21 +01:00
|
|
|
this.handleClosePopover()
|
|
|
|
}
|
|
|
|
|
|
|
|
handleClosePopover = () => {
|
|
|
|
this.props.onClosePopover()
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-12-24 18:27:55 +00:00
|
|
|
const { url, type } = this.state
|
2020-10-24 20:17:21 +01:00
|
|
|
|
2020-12-24 18:27:55 +00:00
|
|
|
if (!url) return <div />
|
2020-10-24 20:17:21 +01:00
|
|
|
|
2020-12-24 18:27:55 +00:00
|
|
|
const encodedUrl = encodeURIComponent(url)
|
|
|
|
const mailToHref = `mailto:?subject=Gab&body=${encodedUrl}`
|
2020-10-30 04:32:06 +00:00
|
|
|
const iconSize = '18px'
|
|
|
|
|
2020-10-24 20:17:21 +01:00
|
|
|
return (
|
2020-10-25 00:50:09 +01:00
|
|
|
<PopoverLayout
|
|
|
|
width={360}
|
|
|
|
>
|
|
|
|
<div className={[_s.d, _s.flexRow, _s.aiCenter, _s.jcCenter, _s.borderBottom1PX, _s.borderColorSecondary, _s.h53PX, _s.px15].join(' ')}>
|
|
|
|
<Heading size='h3'>
|
2020-12-24 18:27:55 +00:00
|
|
|
Share Gab {type}
|
2020-10-25 00:50:09 +01:00
|
|
|
</Heading>
|
|
|
|
</div>
|
|
|
|
<div className={[_s.d, _s.w100PC, _s.px15, _s.py15, _s.flexRow, _s.noScrollbar, _s.aiCenter, _s.overflowXScroll, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}>
|
|
|
|
<Button
|
|
|
|
icon='copy'
|
2020-10-30 04:32:06 +00:00
|
|
|
iconSize={iconSize}
|
2020-10-25 00:50:09 +01:00
|
|
|
iconClassName={_s.inheritFill}
|
2020-10-30 04:32:06 +00:00
|
|
|
color='primary'
|
2020-10-25 00:50:09 +01:00
|
|
|
backgroundColor='secondary'
|
|
|
|
onClick={this.handleCopy}
|
2020-12-24 18:27:55 +00:00
|
|
|
title={`Copy this ${type}`}
|
2020-10-30 04:32:06 +00:00
|
|
|
className={[_s.jcCenter, _s.aiCenter, _s.mr10, _s.px10].join(' ')}
|
2020-10-25 00:50:09 +01:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
icon='sms'
|
2020-10-30 04:32:06 +00:00
|
|
|
iconSize={iconSize}
|
2020-10-25 00:50:09 +01:00
|
|
|
iconClassName={_s.inheritFill}
|
|
|
|
color='white'
|
|
|
|
backgroundColor='none'
|
2020-12-24 18:27:55 +00:00
|
|
|
href={`sms:+&body=${encodedUrl}`}
|
2020-10-30 04:32:06 +00:00
|
|
|
target='_blank'
|
2020-10-25 02:58:48 +00:00
|
|
|
title='Share via text message'
|
2020-10-30 04:32:06 +00:00
|
|
|
className={[_s.jcCenter, _s.aiCenter, _s.mr10, _s.px10, _s.bgSMS].join(' ')}
|
2020-10-25 00:50:09 +01:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
icon='facebook'
|
2020-10-30 04:32:06 +00:00
|
|
|
iconSize={iconSize}
|
2020-10-25 00:50:09 +01:00
|
|
|
iconClassName={_s.inheritFill}
|
|
|
|
color='white'
|
|
|
|
backgroundColor='none'
|
2020-12-24 18:27:55 +00:00
|
|
|
href={`https://www.facebook.com/sharer/sharer.php?u=${encodedUrl}`}
|
2020-10-30 04:32:06 +00:00
|
|
|
target='_blank'
|
2020-10-25 02:58:48 +00:00
|
|
|
title='Share on Facebook'
|
2020-10-30 04:32:06 +00:00
|
|
|
className={[_s.jcCenter, _s.aiCenter, _s.mr10, _s.px10, _s.bgFacebook].join(' ')}
|
2020-10-25 00:50:09 +01:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
icon='twitter'
|
2020-10-30 04:32:06 +00:00
|
|
|
iconSize={iconSize}
|
2020-10-25 00:50:09 +01:00
|
|
|
iconClassName={_s.inheritFill}
|
|
|
|
color='white'
|
|
|
|
backgroundColor='none'
|
2020-12-24 18:27:55 +00:00
|
|
|
href={`https://twitter.com/intent/tweet?url=${encodedUrl}`}
|
2020-10-30 04:32:06 +00:00
|
|
|
target='_blank'
|
2020-10-25 02:58:48 +00:00
|
|
|
title='Share on Twitter'
|
2020-10-30 04:32:06 +00:00
|
|
|
className={[_s.jcCenter, _s.aiCenter, _s.mr10, _s.px10, _s.bgTwitter].join(' ')}
|
2020-10-25 00:50:09 +01:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
icon='telegram'
|
2020-10-30 04:32:06 +00:00
|
|
|
iconSize={iconSize}
|
2020-10-25 00:50:09 +01:00
|
|
|
iconClassName={_s.inheritFill}
|
|
|
|
color='white'
|
|
|
|
backgroundColor='none'
|
2020-12-24 18:27:55 +00:00
|
|
|
href={`https://telegram.me/share/?url=${encodedUrl}`}
|
2020-10-30 04:32:06 +00:00
|
|
|
target='_blank'
|
2020-10-25 02:58:48 +00:00
|
|
|
title='Share on Telegram'
|
2020-10-30 04:32:06 +00:00
|
|
|
className={[_s.jcCenter, _s.aiCenter, _s.mr10, _s.px10, _s.bgTelegram].join(' ')}
|
2020-10-25 00:50:09 +01:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
icon='reddit'
|
2020-10-30 04:32:06 +00:00
|
|
|
iconSize={iconSize}
|
2020-10-25 00:50:09 +01:00
|
|
|
iconClassName={_s.inheritFill}
|
|
|
|
color='white'
|
|
|
|
backgroundColor='none'
|
2020-12-24 18:27:55 +00:00
|
|
|
href={`http://www.reddit.com/submit?url=${encodedUrl}&title=Gab`}
|
2020-10-25 02:58:48 +00:00
|
|
|
title='Share on Reddit'
|
2020-10-30 04:32:06 +00:00
|
|
|
target='_blank'
|
|
|
|
className={[_s.jcCenter, _s.aiCenter, _s.px10, _s.mr10, _s.bgReddit].join(' ')}
|
2020-10-25 00:50:09 +01:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
icon='email'
|
2020-10-30 04:32:06 +00:00
|
|
|
iconSize={iconSize}
|
2020-10-25 00:50:09 +01:00
|
|
|
iconClassName={_s.inheritFill}
|
|
|
|
color='white'
|
|
|
|
backgroundColor='black'
|
2020-10-25 02:58:48 +00:00
|
|
|
href={mailToHref}
|
2020-10-30 04:32:06 +00:00
|
|
|
target='_blank'
|
2020-10-25 02:58:48 +00:00
|
|
|
title='Share via email'
|
2020-10-25 00:50:09 +01:00
|
|
|
className={[_s.jcCenter, _s.aiCenter, _s.mr10, _s.px10].join(' ')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className={[_s.d, _s.w100PC, _s.px15, _s.py15].join(' ')}>
|
|
|
|
<Button
|
|
|
|
color='primary'
|
|
|
|
backgroundColor='tertiary'
|
|
|
|
onClick={this.handleClosePopover}
|
|
|
|
className={[_s.jcCenter, _s.aiCenter].join(' ')}
|
|
|
|
>
|
|
|
|
<Text color='inherit'>Cancel</Text>
|
|
|
|
</Button>
|
|
|
|
</div>
|
2020-10-24 20:17:21 +01:00
|
|
|
</PopoverLayout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onClosePopover: () => dispatch(closePopover()),
|
2020-12-16 00:31:30 +00:00
|
|
|
onShowCopyToast() {
|
2020-12-24 18:27:55 +00:00
|
|
|
dispatch(showToast(TOAST_TYPE_SUCCESS, {
|
|
|
|
type: "SUCCESSFULLY_COPIED_TO_CLIPBOARD"
|
|
|
|
}))
|
2020-12-16 00:31:30 +00:00
|
|
|
},
|
2020-10-24 20:17:21 +01:00
|
|
|
})
|
|
|
|
|
2020-12-24 18:27:55 +00:00
|
|
|
SharePopover.propTypes = {
|
2020-10-24 20:17:21 +01:00
|
|
|
onClosePopover: PropTypes.func.isRequired,
|
2020-12-24 18:27:55 +00:00
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
group: ImmutablePropTypes.map,
|
|
|
|
status: ImmutablePropTypes.map,
|
2020-10-24 20:17:21 +01:00
|
|
|
}
|
|
|
|
|
2020-12-24 18:27:55 +00:00
|
|
|
export default connect(null, mapDispatchToProps)(SharePopover)
|