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

99 lines
2.9 KiB
JavaScript
Raw Normal View History

2020-03-27 22:57:03 +00:00
import { defineMessages, injectIntl } from 'react-intl'
import ImmutablePropTypes from 'react-immutable-proptypes'
import ImmutablePureComponent from 'react-immutable-pure-component'
import classNames from 'classnames/bind'
import { loadStatusRevisions } from '../../actions/status_revisions'
import ModalLayout from './modal_layout'
import RelativeTimestamp from '../relative_timestamp'
import ScrollableList from '../scrollable_list'
import Text from '../text'
const cx = classNames.bind(_s)
const messages = defineMessages({
title: { id: 'status_revisions.heading', defaultMessage: 'Revision History' },
})
2020-04-11 23:29:19 +01:00
const mapStateToProps = (state) => ({
2020-03-27 22:57:03 +00:00
loading: state.getIn(['status_revisions', 'loading']),
error: state.getIn(['status_revisions', 'error']),
revisions: state.getIn(['status_revisions', 'revisions']),
})
2020-04-11 23:29:19 +01:00
const mapDispatchToProps = (dispatch) => ({
2020-03-27 22:57:03 +00:00
onLoadStatusRevisions(statusId) {
dispatch(loadStatusRevisions(statusId))
},
})
export default
@injectIntl
@connect(mapStateToProps, mapDispatchToProps)
class StatusRevisionsModal extends ImmutablePureComponent {
static propTypes = {
intl: PropTypes.object.isRequired,
status: ImmutablePropTypes.map.isRequired,
onLoadStatusRevisions: PropTypes.func.isRequired,
loading: PropTypes.bool.isRequired,
error: PropTypes.bool,
revisions: ImmutablePropTypes.list.isRequired,
2020-04-07 02:53:23 +01:00
onClose: PropTypes.func.isRequired,
2020-03-27 22:57:03 +00:00
}
componentDidMount() {
this.props.onLoadStatusRevisions(this.props.status.get('id'))
}
render() {
const {
intl,
status,
2020-04-07 02:53:23 +01:00
revisions,
onClose
2020-03-27 22:57:03 +00:00
} = this.props
return (
2020-04-07 02:53:23 +01:00
<ModalLayout
title={intl.formatMessage(messages.title)}
width='480'
onClose={onClose}
>
2020-03-27 22:57:03 +00:00
<div className={[_s.default]}>
<ScrollableList>
{
revisions.map((revision, i) => {
const isFirst = i === 0
const isLast = i === revisions.size - 1
const containerClasses = cx({
default: 1,
pt5: 1,
pb10: 1,
mt5: !isFirst,
borderColorSecondary: !isLast,
borderBottom1PX: !isLast,
})
return (
<div key={`status-revision-${i}`} className={containerClasses}>
<div className={[_s.default, _s.pb5].join(' ')}>
<Text size='medium'>
{revision.get('text')}
</Text>
</div>
<div className={[_s.default]}>
<Text size='small' color='secondary'>
Edited on <RelativeTimestamp timestamp={revision.get('created_at')} />
</Text>
</div>
</div>
)
})
}
</ScrollableList>
</div>
</ModalLayout>
)
}
}