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'
|
2019-07-02 08:10:25 +01:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2019-08-13 16:54:29 +01:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2019-08-07 06:02:36 +01:00
|
|
|
import { Set as ImmutableSet } from 'immutable';
|
2020-11-25 21:22:37 +00:00
|
|
|
import noop from 'lodash.noop'
|
2020-03-24 04:39:12 +00:00
|
|
|
import { toggleStatusReport } from '../actions/reports';
|
2020-03-25 03:08:43 +00:00
|
|
|
import { MediaGallery, Video } from '../features/ui/util/async_components';
|
2020-03-24 04:39:12 +00:00
|
|
|
import Bundle from '../features/ui/util/bundle';
|
|
|
|
import StatusContent from './status_content';
|
|
|
|
import Switch from './switch';
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2019-08-13 16:54:29 +01:00
|
|
|
class StatusCheckBox extends ImmutablePureComponent {
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
render () {
|
|
|
|
const { status, checked, onToggle, disabled } = this.props;
|
|
|
|
let media = null;
|
|
|
|
|
2020-03-24 04:39:12 +00:00
|
|
|
if (status.get('reblog')) return null
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
if (status.get('media_attachments').size > 0) {
|
|
|
|
if (status.get('media_attachments').some(item => item.get('type') === 'unknown')) {
|
|
|
|
|
|
|
|
} else if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
|
|
|
|
const video = status.getIn(['media_attachments', 0]);
|
|
|
|
|
|
|
|
media = (
|
|
|
|
<Bundle fetchComponent={Video} loading={this.renderLoadingVideoPlayer} >
|
|
|
|
{Component => (
|
|
|
|
<Component
|
|
|
|
preview={video.get('preview_url')}
|
|
|
|
blurhash={video.get('blurhash')}
|
|
|
|
src={video.get('url')}
|
2020-12-22 17:11:22 +00:00
|
|
|
sourceMp4={video.get('source_mp4')}
|
2019-07-02 08:10:25 +01:00
|
|
|
alt={video.get('description')}
|
2019-08-23 05:03:17 +01:00
|
|
|
aspectRatio={video.getIn(['meta', 'small', 'aspect'])}
|
2020-12-22 06:36:38 +00:00
|
|
|
fileContentType={video.get('file_content_type')}
|
2019-07-02 08:10:25 +01:00
|
|
|
width={239}
|
|
|
|
height={110}
|
|
|
|
inline
|
|
|
|
sensitive={status.get('sensitive')}
|
|
|
|
onOpenVideo={noop}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Bundle>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
media = (
|
|
|
|
<Bundle fetchComponent={MediaGallery} loading={this.renderLoadingMediaGallery} >
|
2020-12-20 17:27:24 +00:00
|
|
|
{Component => (
|
|
|
|
<Component
|
|
|
|
media={status.get('media_attachments')}
|
|
|
|
sensitive={status.get('sensitive')}
|
|
|
|
onOpenMedia={noop}
|
|
|
|
width={239}
|
|
|
|
height={110}
|
|
|
|
/>
|
|
|
|
)}
|
2019-07-02 08:10:25 +01:00
|
|
|
</Bundle>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-12-20 17:27:24 +00:00
|
|
|
<div className={[_s.d, _s.flexRow, _s.flexWrap, _s.borderBottom1PX, _s.borderColorSecondary, _s.aiStart, _s.mb5, _s.pr15, _s.pt5, _s.w100PC].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.pt5, _s.maxW100PC].join(' ')}>
|
2019-07-02 08:10:25 +01:00
|
|
|
<StatusContent status={status} />
|
2020-12-20 17:27:24 +00:00
|
|
|
<div className={_s.pl15}>
|
|
|
|
{media}
|
|
|
|
</div>
|
2019-07-02 08:10:25 +01:00
|
|
|
</div>
|
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.mlAuto].join(' ')}>
|
2020-03-24 04:39:12 +00:00
|
|
|
<Switch checked={checked} onChange={onToggle} disabled={disabled} />
|
2019-07-02 08:10:25 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-03-24 04:39:12 +00:00
|
|
|
)
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-18 01:57:35 +01:00
|
|
|
|
|
|
|
const mapStateToProps = (state, { id }) => ({
|
|
|
|
status: state.getIn(['statuses', id]),
|
|
|
|
checked: state.getIn(['reports', 'new', 'status_ids'], ImmutableSet()).includes(id),
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch, { id }) => ({
|
2020-09-01 20:54:17 +01:00
|
|
|
onToggle(checked) {
|
|
|
|
dispatch(toggleStatusReport(id, checked))
|
2020-08-18 01:57:35 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
StatusCheckBox.propTypes = {
|
|
|
|
status: ImmutablePropTypes.map.isRequired,
|
|
|
|
checked: PropTypes.bool,
|
|
|
|
onToggle: PropTypes.func.isRequired,
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(StatusCheckBox)
|