2016-11-14 05:08:52 +11:00
|
|
|
import { connect } from 'react-redux';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
2016-11-14 05:08:52 +11:00
|
|
|
import { uploadCompose } from '../../../actions/compose';
|
2023-05-24 01:15:17 +10:00
|
|
|
import UploadButton from '../components/upload_button';
|
2016-11-14 05:08:52 +11:00
|
|
|
|
2024-03-06 23:53:54 +11: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;
|
2024-07-08 18:10:57 +10:00
|
|
|
const isOverLimit = attachmentsSize > state.getIn(['server', 'server', 'configuration', 'statuses', 'max_media_attachments'])-1;
|
2024-03-06 23:53:54 +11:00
|
|
|
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 05:08:52 +11:00
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
|
2024-03-06 23:53:54 +11:00
|
|
|
onSelectFile(files) {
|
2016-11-14 05:08:52 +11:00
|
|
|
dispatch(uploadCompose(files));
|
2017-05-21 01:31:47 +10:00
|
|
|
},
|
2016-11-14 05:08:52 +11:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(UploadButton);
|