gab-social/app/javascript/gabsocial/components/status_check_box.js

87 lines
2.8 KiB
JavaScript
Raw Normal View History

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';
import { Set as ImmutableSet } from 'immutable';
2019-07-02 08:10:25 +01:00
import noop from 'lodash/noop';
2020-03-24 04:39:12 +00:00
import { toggleStatusReport } from '../actions/reports';
import { MediaGallery, Video } from '../features/ui/util/async-components';
import Bundle from '../features/ui/util/bundle';
import StatusContent from './status_content';
import Switch from './switch';
2019-07-02 08:10:25 +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 }) => ({
onToggle(e) {
dispatch(toggleStatusReport(id, e.target.checked));
},
});
2020-02-25 16:04:44 +00:00
export default
@connect(mapStateToProps, mapDispatchToProps)
2019-08-13 16:54:29 +01:00
class StatusCheckBox extends ImmutablePureComponent {
2019-07-02 08:10:25 +01:00
static propTypes = {
status: ImmutablePropTypes.map.isRequired,
checked: PropTypes.bool,
onToggle: PropTypes.func.isRequired,
disabled: PropTypes.bool,
};
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')}
alt={video.get('description')}
aspectRatio={video.getIn(['meta', 'small', 'aspect'])}
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} >
{Component => <Component media={status.get('media_attachments')} sensitive={status.get('sensitive')} height={110} onOpenMedia={noop} />}
</Bundle>
);
}
}
return (
2020-03-24 04:39:12 +00:00
<div className={[_s.default, _s.flexRow].join(' ')}>
<div className={[_s.default].join(' ')}>
2019-07-02 08:10:25 +01:00
<StatusContent status={status} />
{media}
</div>
2020-03-24 04:39:12 +00:00
<div className={[_s.default, _s.marginLeftAuto].join(' ')}>
<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
}
}