2016-11-14 03:08:52 +09:00
|
|
|
import { connect } from 'react-redux';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
2016-11-14 03:08:52 +09:00
|
|
|
import { uploadCompose } from '../../../actions/compose';
|
2023-05-24 00:15:17 +09:00
|
|
|
import UploadButton from '../components/upload_button';
|
2016-11-14 03:08:52 +09:00
|
|
|
|
2024-03-06 21:53:54 +09:00
|
|
|
const mapStateToProps = state => {
|
|
|
|
const isPoll = state.getIn(['compose', 'poll']) !== null;
|
|
|
|
const isUploading = state.getIn(['compose', 'is_uploading']);
|
|
|
|
const readyAttachmentsSize = state.getIn(['compose', 'media_attachments']).size ?? 0;
|
|
|
|
const pendingAttachmentsSize = state.getIn(['compose', 'pending_media_attachments']).size ?? 0;
|
|
|
|
const attachmentsSize = readyAttachmentsSize + pendingAttachmentsSize;
|
|
|
|
const isOverLimit = attachmentsSize > 3;
|
|
|
|
const hasVideoOrAudio = state.getIn(['compose', 'media_attachments']).some(m => ['video', 'audio'].includes(m.get('type')));
|
|
|
|
|
|
|
|
return {
|
|
|
|
disabled: isPoll || isUploading || isOverLimit || hasVideoOrAudio,
|
|
|
|
resetFileKey: state.getIn(['compose', 'resetFileKey']),
|
|
|
|
};
|
|
|
|
};
|
2016-11-14 03:08:52 +09:00
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
|
2024-03-06 21:53:54 +09:00
|
|
|
onSelectFile(files) {
|
2016-11-14 03:08:52 +09:00
|
|
|
dispatch(uploadCompose(files));
|
2017-05-21 00:31:47 +09:00
|
|
|
},
|
2016-11-14 03:08:52 +09:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(UploadButton);
|