Skip to content

Commit 2fe105e

Browse files
committed
Fix unhandeled nullable attachements counter
1 parent 819ede1 commit 2fe105e

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

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

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
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+
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+
};
1021

1122
const mapDispatchToProps = dispatch => ({
1223

13-
onSelectFile (files) {
24+
onSelectFile(files) {
1425
dispatch(uploadCompose(files));
1526
},
1627

0 commit comments

Comments
 (0)