2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
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'
|
2020-12-10 16:51:45 +00:00
|
|
|
import ComposeFormSubmitButton from '../../features/compose/components/compose_form_submit_button'
|
2020-03-11 23:56:18 +00:00
|
|
|
import TimelineComposeBlock from '../timeline_compose_block'
|
2020-12-09 20:02:43 +00:00
|
|
|
import Block from '../block'
|
|
|
|
import Heading from '../heading'
|
|
|
|
import Button from '../button'
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
class ComposeModal extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
onClickClose = () => {
|
2020-05-07 00:40:54 +01:00
|
|
|
const {
|
|
|
|
composeText,
|
|
|
|
dispatch,
|
|
|
|
onClose,
|
|
|
|
intl,
|
|
|
|
} = this.props
|
2019-07-23 04:10:05 +01:00
|
|
|
|
|
|
|
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." />,
|
2019-07-23 04:10:05 +01:00
|
|
|
confirm: intl.formatMessage(messages.confirm),
|
|
|
|
onConfirm: () => dispatch(cancelReplyCompose()),
|
|
|
|
onCancel: () => dispatch(openModal('COMPOSE')),
|
2020-05-07 00:40:54 +01:00
|
|
|
}))
|
2019-07-23 04:10:05 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-05-07 00:40:54 +01:00
|
|
|
onClose('COMPOSE')
|
2019-07-23 04:10:05 +01:00
|
|
|
}
|
2020-05-07 00:40:54 +01:00
|
|
|
}
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-12-09 20:02:43 +00:00
|
|
|
onHandleSubmit = () => {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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-12-16 00:31:30 +00:00
|
|
|
<div style={{width: '580px'}} className={[_s.d, _s.modal].join(' ')}>
|
2020-12-09 20:02:43 +00:00
|
|
|
<Block>
|
2020-12-16 00:31:30 +00:00
|
|
|
<div className={[_s.d, _s.flexRow, _s.aiCenter, _s.jcCenter, _s.borderBottom1PX, _s.borderColorSecondary, _s.h53PX, _s.pl5, _s.pr10].join(' ')}>
|
2020-12-10 16:51:45 +00:00
|
|
|
<div className={[_s.d, _s.w115PX, _s.aiStart, _s.jcCenter, _s.mrAuto].join(' ')}>
|
|
|
|
<Button
|
|
|
|
backgroundColor='none'
|
|
|
|
title={intl.formatMessage(messages.close)}
|
|
|
|
onClick={this.onClickClose}
|
|
|
|
color='secondary'
|
|
|
|
icon='close'
|
|
|
|
iconSize='10px'
|
|
|
|
/>
|
|
|
|
</div>
|
2020-12-09 20:02:43 +00:00
|
|
|
<Heading size='h2'>
|
|
|
|
{intl.formatMessage(title)}
|
|
|
|
</Heading>
|
2020-12-10 16:51:45 +00:00
|
|
|
<div className={[_s.d, _s.w115PX, _s.aiEnd, _s.jcCenter, _s.mlAuto].join(' ')}>
|
|
|
|
<ComposeFormSubmitButton type='header' />
|
|
|
|
</div>
|
2020-12-09 20:02:43 +00:00
|
|
|
</div>
|
2020-12-16 00:31:30 +00:00
|
|
|
<div className={[_s.d, _s.pt5].join(' ')}>
|
|
|
|
<TimelineComposeBlock isModal formLocation='modal' />
|
2020-12-09 20:02:43 +00:00
|
|
|
</div>
|
|
|
|
</Block>
|
|
|
|
</div>
|
2020-05-07 00:40:54 +01:00
|
|
|
)
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
2020-01-28 16:29:37 +00:00
|
|
|
}
|
2020-08-18 18:07:47 +01:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
confirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
|
|
|
|
title: { id: 'navigation_bar.compose', defaultMessage: 'Compose new gab' },
|
|
|
|
comment: { id: 'navigation_bar.compose_comment', defaultMessage: 'Compose new comment' },
|
|
|
|
edit: { id: 'navigation_bar.edit_gab', defaultMessage: 'Edit' },
|
2020-12-09 20:02:43 +00:00
|
|
|
close: { id: 'lightbox.close', defaultMessage: 'Close' },
|
2020-08-18 18:07:47 +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']),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ComposeModal.propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
composeText: PropTypes.string,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
isEditing: PropTypes.bool,
|
|
|
|
isComment: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps)(ComposeModal))
|