gab-social/app/javascript/gabsocial/components/modal/compose_modal.js

81 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-03-11 23:56:18 +00:00
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'
import ImmutablePureComponent from 'react-immutable-pure-component'
import { openModal } from '../../actions/modal'
import { cancelReplyCompose } from '../../actions/compose'
import ModalLayout from './modal_layout'
import TimelineComposeBlock from '../timeline_compose_block'
2019-07-02 08:10:25 +01:00
const messages = defineMessages({
confirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
title: { id: 'navigation_bar.compose', defaultMessage: 'Compose new gab' },
2020-05-07 00:40:54 +01:00
comment: { id: 'navigation_bar.compose_comment', defaultMessage: 'Compose new comment' },
edit: { id: 'navigation_bar.edit_gab', defaultMessage: 'Edit' },
2020-03-11 23:56:18 +00:00
})
2019-07-02 08:10:25 +01:00
2020-05-07 00:40:54 +01:00
const mapStateToProps = (state) => {
const status = state.getIn(['statuses', state.getIn(['compose', 'id'])])
return {
composeText: state.getIn(['compose', 'text']),
isEditing: !!status,
isComment: !!state.getIn(['compose', 'in_reply_to']),
}
}
2019-07-02 08:10:25 +01:00
2020-02-25 16:04:44 +00:00
export default
@connect(mapStateToProps)
@injectIntl
2019-07-02 08:10:25 +01:00
class ComposeModal extends ImmutablePureComponent {
static propTypes = {
intl: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired,
composeText: PropTypes.string,
dispatch: PropTypes.func.isRequired,
2020-05-07 00:40:54 +01:00
isEditing: PropTypes.bool,
isComment: PropTypes.bool,
}
2019-07-02 08:10:25 +01:00
onClickClose = () => {
2020-05-07 00:40:54 +01:00
const {
composeText,
dispatch,
onClose,
intl,
} = this.props
if (composeText) {
dispatch(openModal('CONFIRM', {
2020-03-11 23:56:18 +00:00
title: <FormattedMessage id='discard-gab-title' defaultMessage='Discard gab?' />,
message: <FormattedMessage id='discard-gab-message' defaultMessage="This can't be undone and you'll lose your draft." />,
confirm: intl.formatMessage(messages.confirm),
onConfirm: () => dispatch(cancelReplyCompose()),
onCancel: () => dispatch(openModal('COMPOSE')),
2020-05-07 00:40:54 +01:00
}))
}
else {
2020-05-07 00:40:54 +01:00
onClose('COMPOSE')
}
2020-05-07 00:40:54 +01:00
}
2019-07-02 08:10:25 +01:00
2020-03-07 04:53:28 +00:00
render() {
2020-05-07 00:40:54 +01:00
const {
intl,
isEditing,
isComment,
} = this.props
const title = isEditing ? messages.edit : isComment ? messages.comment : messages.title
2019-07-02 08:10:25 +01:00
return (
2020-03-07 04:53:28 +00:00
<ModalLayout
noPadding
2020-05-07 00:40:54 +01:00
title={intl.formatMessage(title)}
2020-03-12 16:09:15 +00:00
onClose={this.onClickClose}
2020-03-07 04:53:28 +00:00
>
<TimelineComposeBlock modal />
</ModalLayout>
2020-05-07 00:40:54 +01:00
)
2019-07-02 08:10:25 +01:00
}
2020-01-28 16:29:37 +00:00
}