From b8bd94ca8edb5a675ef70aac9c941ed340efc127 Mon Sep 17 00:00:00 2001 From: Mashiro Date: Wed, 6 Mar 2024 20:53:54 +0800 Subject: [PATCH] Fix unhandled nullable attachments limitation counter (#29183) --- .../containers/upload_button_container.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/javascript/mastodon/features/compose/containers/upload_button_container.js b/app/javascript/mastodon/features/compose/containers/upload_button_container.js index 7c4757b6c3..066e185346 100644 --- a/app/javascript/mastodon/features/compose/containers/upload_button_container.js +++ b/app/javascript/mastodon/features/compose/containers/upload_button_container.js @@ -3,14 +3,24 @@ import { connect } from 'react-redux'; import { uploadCompose } from '../../../actions/compose'; import UploadButton from '../components/upload_button'; -const mapStateToProps = state => ({ - 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')))), - resetFileKey: state.getIn(['compose', 'resetFileKey']), -}); +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']), + }; +}; const mapDispatchToProps = dispatch => ({ - onSelectFile (files) { + onSelectFile(files) { dispatch(uploadCompose(files)); },