|
1 |
| -import { connect } from 'react-redux'; |
| 1 | +import {connect} from 'react-redux'; |
2 | 2 |
|
3 |
| -import { uploadCompose } from '../../../actions/compose'; |
| 3 | +import {uploadCompose} from '../../../actions/compose'; |
4 | 4 | import UploadButton from '../components/upload_button';
|
5 | 5 |
|
6 |
| -const mapStateToProps = state => ({ |
7 |
| - disabled: state.getIn(['compose', 'poll']) !== null || state.getIn(['compose', 'is_uploading']) || (state.getIn(['compose', 'media_attachments']).size + state.getIn(['compose', 'pending_media_attachments']) > 3 || state.getIn(['compose', 'media_attachments']).some(m => ['video', 'audio'].includes(m.get('type')))), |
8 |
| - resetFileKey: state.getIn(['compose', 'resetFileKey']), |
9 |
| -}); |
| 6 | +const mapStateToProps = state => { |
| 7 | + const isPoll = state.getIn(['compose', 'poll']) !== null; |
| 8 | + const isUploading = state.getIn(['compose', 'is_uploading']); |
| 9 | + const readyAttachmentsSize = state.getIn(['compose', 'media_attachments']).size ?? 0; |
| 10 | + const pendingAttachmentsSize = state.getIn(['compose', 'pending_media_attachments']).size ?? 0; |
| 11 | + const attachmentsSize = readyAttachmentsSize + pendingAttachmentsSize; |
| 12 | + console.log('attachmentsSize:', attachmentsSize, readyAttachmentsSize, pendingAttachmentsSize); |
| 13 | + const isOverLimit = attachmentsSize > 3; |
| 14 | + const hasVideoOrAudio = state.getIn(['compose', 'media_attachments']).some(m => ['video', 'audio'].includes(m.get('type'))); |
| 15 | + |
| 16 | + return { |
| 17 | + disabled: isPoll || isUploading || isOverLimit || hasVideoOrAudio, |
| 18 | + resetFileKey: state.getIn(['compose', 'resetFileKey']), |
| 19 | + }; |
| 20 | +}; |
10 | 21 |
|
11 | 22 | const mapDispatchToProps = dispatch => ({
|
12 | 23 |
|
13 |
| - onSelectFile (files) { |
| 24 | + onSelectFile(files) { |
14 | 25 | dispatch(uploadCompose(files));
|
15 | 26 | },
|
16 | 27 |
|
|
0 commit comments