Skip to content

Commit 84b5b14

Browse files
committed
Fix unhandeled nullable attachements counter
1 parent 819ede1 commit 84b5b14

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

app/javascript/mastodon/features/compose/containers/upload_button_container.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
import { connect } from 'react-redux';
1+
import {connect} from 'react-redux';
22

3-
import { uploadCompose } from '../../../actions/compose';
3+
import {uploadCompose} from '../../../actions/compose';
44
import UploadButton from '../components/upload_button';
55

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+
const isOverLimit = attachmentsSize > 3;
13+
const hasVideoOrAudio = state.getIn(['compose', 'media_attachments']).some(m => ['video', 'audio'].includes(m.get('type')));
14+
15+
return {
16+
disabled: isPoll || isUploading || isOverLimit || hasVideoOrAudio,
17+
resetFileKey: state.getIn(['compose', 'resetFileKey']),
18+
};
19+
};
1020

1121
const mapDispatchToProps = dispatch => ({
1222

13-
onSelectFile (files) {
23+
onSelectFile(files) {
1424
dispatch(uploadCompose(files));
1525
},
1626

0 commit comments

Comments
 (0)