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

125 lines
3.5 KiB
JavaScript
Raw Normal View History

2020-04-24 04:17:27 +01:00
import ImmutablePureComponent from 'react-immutable-pure-component'
import ImmutablePropTypes from 'react-immutable-proptypes'
import { defineMessages, injectIntl } from 'react-intl'
2020-05-01 06:50:27 +01:00
import {
MODAL_BOOST,
MODAL_CONFIRM,
MODAL_UNAUTHORIZED,
} from '../../constants'
import { boostModal, me } from '../../initial_state'
2020-04-24 04:17:27 +01:00
import { quoteCompose } from '../../actions/compose'
import { repost, unrepost } from '../../actions/interactions'
2020-05-01 06:50:27 +01:00
import { closePopover } from '../../actions/popover'
2020-04-24 04:17:27 +01:00
import { openModal } from '../../actions/modal'
import PopoverLayout from './popover_layout'
import List from '../list'
const messages = defineMessages({
repost: { id: 'repost', defaultMessage: 'Repost' },
2020-05-01 06:50:27 +01:00
removeRepost: { id: 'status.cancel_repost_private', defaultMessage: 'Remove Repost' },
2020-04-24 04:17:27 +01:00
repostWithComment: { id: 'repost_with_comment', defaultMessage: 'Repost with comment' },
2020-05-01 06:50:27 +01:00
quoteMessage: { id: 'confirmations.quote.message', defaultMessage: 'Quoting now will overwrite the message you are currently composing. Are you sure you want to proceed?' },
quoteConfirm: { id: 'confirmations.quote.confirm', defaultMessage: 'Quote' },
})
2020-04-24 04:17:27 +01:00
const mapDispatchToProps = (dispatch, { intl }) => ({
onQuote (status, router) {
2020-05-01 06:50:27 +01:00
if (!me) return dispatch(openModal(MODAL_UNAUTHORIZED))
dispatch(closePopover())
2020-04-24 04:17:27 +01:00
dispatch((_, getState) => {
2020-05-01 06:50:27 +01:00
const state = getState()
2020-04-24 04:17:27 +01:00
if (state.getIn(['compose', 'text']).trim().length !== 0) {
2020-05-01 06:50:27 +01:00
dispatch(openModal(MODAL_CONFIRM, {
2020-04-24 04:17:27 +01:00
message: intl.formatMessage(messages.quoteMessage),
confirm: intl.formatMessage(messages.quoteConfirm),
onConfirm: () => dispatch(quoteCompose(status, router)),
2020-05-01 06:50:27 +01:00
}))
2020-04-24 04:17:27 +01:00
} else {
2020-05-01 06:50:27 +01:00
dispatch(quoteCompose(status, router))
2020-04-24 04:17:27 +01:00
}
2020-05-01 06:50:27 +01:00
})
2020-04-24 04:17:27 +01:00
},
onRepost (status) {
2020-05-01 06:50:27 +01:00
if (!me) return dispatch(openModal(MODAL_UNAUTHORIZED))
2020-04-24 04:17:27 +01:00
2020-05-01 06:50:27 +01:00
dispatch(closePopover())
const alreadyReposted = status.get('reblogged')
if (boostModal && !alreadyReposted) {
dispatch(openModal(MODAL_BOOST, {
status,
onRepost: () => dispatch(repost(status)),
}))
2020-04-24 04:17:27 +01:00
} else {
2020-05-01 06:50:27 +01:00
if (alreadyReposted) {
dispatch(unrepost(status))
} else {
dispatch(repost(status))
}
2020-04-24 04:17:27 +01:00
}
},
2020-05-01 06:50:27 +01:00
})
2020-04-24 04:17:27 +01:00
export default
@injectIntl
@connect(null, mapDispatchToProps)
class RepostOptionsPopover extends ImmutablePureComponent {
2020-05-01 06:50:27 +01:00
static contextTypes = {
router: PropTypes.object,
}
2020-04-24 04:17:27 +01:00
static defaultProps = {
intl: PropTypes.object.isRequired,
onQuote: PropTypes.func.isRequired,
onRepost: PropTypes.func.isRequired,
2020-05-01 06:50:27 +01:00
status: ImmutablePropTypes.map.isRequired,
isXS: PropTypes.bool,
2020-04-24 04:17:27 +01:00
}
2020-05-01 06:50:27 +01:00
updateOnProps = [
'status',
]
2020-04-24 04:17:27 +01:00
2020-05-01 06:50:27 +01:00
handleOnQuote = () => {
2020-05-15 04:17:31 +01:00
this.props.onQuote(this.props.status, this.context.router)
2020-04-24 04:17:27 +01:00
}
2020-05-01 06:50:27 +01:00
handleOnRepost = () => {
this.props.onRepost(this.props.status)
2020-04-24 04:17:27 +01:00
}
render() {
const { intl, status, isXS } = this.props
2020-04-24 04:17:27 +01:00
2020-05-01 06:50:27 +01:00
const alreadyReposted = status.get('reblogged')
2020-04-24 04:17:27 +01:00
return (
<PopoverLayout width={220} isXS={isXS}>
2020-04-24 04:17:27 +01:00
<List
scrollKey='repost_options'
size='large'
2020-05-01 06:50:27 +01:00
items={[
{
hideArrow: true,
icon: 'repost',
title: intl.formatMessage(!alreadyReposted ? messages.repost : messages.removeRepost),
onClick: this.handleOnRepost,
},
{
hideArrow: true,
icon: 'pencil',
title: intl.formatMessage(messages.repostWithComment),
onClick: this.handleOnQuote,
}
]}
2020-04-24 04:17:27 +01:00
/>
</PopoverLayout>
)
}
}