Remove text requirement when media attached from statuses (fixes #381)
Ports cfa9b6e13a
to glitchsoc
This commit is contained in:
parent
a0724cd742
commit
841ef606a9
4 changed files with 19 additions and 7 deletions
|
@ -102,8 +102,9 @@ export function mentionCompose(account, router) {
|
||||||
export function submitCompose() {
|
export function submitCompose() {
|
||||||
return function (dispatch, getState) {
|
return function (dispatch, getState) {
|
||||||
let status = getState().getIn(['compose', 'text'], '');
|
let status = getState().getIn(['compose', 'text'], '');
|
||||||
|
let media = getState().getIn(['compose', 'media_attachments']);
|
||||||
|
|
||||||
if (!status || !status.length) {
|
if ((!status || !status.length) && media.size === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +115,7 @@ export function submitCompose() {
|
||||||
api(getState).post('/api/v1/statuses', {
|
api(getState).post('/api/v1/statuses', {
|
||||||
status,
|
status,
|
||||||
in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null),
|
in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null),
|
||||||
media_ids: getState().getIn(['compose', 'media_attachments']).map(item => item.get('id')),
|
media_ids: media.map(item => item.get('id')),
|
||||||
sensitive: getState().getIn(['compose', 'sensitive']),
|
sensitive: getState().getIn(['compose', 'sensitive']),
|
||||||
spoiler_text: getState().getIn(['compose', 'spoiler_text'], ''),
|
spoiler_text: getState().getIn(['compose', 'spoiler_text'], ''),
|
||||||
visibility: getState().getIn(['compose', 'privacy']),
|
visibility: getState().getIn(['compose', 'privacy']),
|
||||||
|
|
|
@ -24,6 +24,11 @@ export default class StatusContent extends React.PureComponent {
|
||||||
|
|
||||||
_updateStatusLinks () {
|
_updateStatusLinks () {
|
||||||
const node = this.node;
|
const node = this.node;
|
||||||
|
|
||||||
|
if (!node) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const links = node.querySelectorAll('a');
|
const links = node.querySelectorAll('a');
|
||||||
|
|
||||||
for (var i = 0; i < links.length; ++i) {
|
for (var i = 0; i < links.length; ++i) {
|
||||||
|
@ -126,6 +131,10 @@ export default class StatusContent extends React.PureComponent {
|
||||||
disabled,
|
disabled,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
if (status.get('content').length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const hidden = this.props.setExpansion ? !this.props.expanded : this.state.hidden;
|
const hidden = this.props.setExpansion ? !this.props.expanded : this.state.hidden;
|
||||||
|
|
||||||
const content = { __html: status.get('contentHtml') };
|
const content = { __html: status.get('contentHtml') };
|
||||||
|
|
|
@ -73,6 +73,7 @@ function mapStateToProps (state) {
|
||||||
suggestionToken: state.getIn(['compose', 'suggestion_token']),
|
suggestionToken: state.getIn(['compose', 'suggestion_token']),
|
||||||
suggestions: state.getIn(['compose', 'suggestions']),
|
suggestions: state.getIn(['compose', 'suggestions']),
|
||||||
text: state.getIn(['compose', 'text']),
|
text: state.getIn(['compose', 'text']),
|
||||||
|
anyMedia: state.getIn(['compose', 'media_attachments']).size > 0,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -272,6 +273,7 @@ class Composer extends React.Component {
|
||||||
acceptContentTypes,
|
acceptContentTypes,
|
||||||
advancedOptions,
|
advancedOptions,
|
||||||
amUnlocked,
|
amUnlocked,
|
||||||
|
anyMedia,
|
||||||
intl,
|
intl,
|
||||||
isSubmitting,
|
isSubmitting,
|
||||||
isUploading,
|
isUploading,
|
||||||
|
@ -305,6 +307,8 @@ class Composer extends React.Component {
|
||||||
text,
|
text,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
let disabledButton = isSubmitting || isUploading || (!!text.length && !text.trim().length && !anyMedia);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='composer'>
|
<div className='composer'>
|
||||||
<ComposerSpoiler
|
<ComposerSpoiler
|
||||||
|
@ -374,7 +378,7 @@ class Composer extends React.Component {
|
||||||
/>
|
/>
|
||||||
<ComposerPublisher
|
<ComposerPublisher
|
||||||
countText={`${spoilerText}${countableText(text)}${advancedOptions && advancedOptions.get('do_not_federate') ? ' 👁️' : ''}`}
|
countText={`${spoilerText}${countableText(text)}${advancedOptions && advancedOptions.get('do_not_federate') ? ' 👁️' : ''}`}
|
||||||
disabled={isSubmitting || isUploading || !!text.length && !text.trim().length}
|
disabled={disabledButton}
|
||||||
intl={intl}
|
intl={intl}
|
||||||
onSecondarySubmit={handleSecondarySubmit}
|
onSecondarySubmit={handleSecondarySubmit}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
|
@ -436,6 +440,7 @@ Composer.propTypes = {
|
||||||
onUndoUpload: PropTypes.func,
|
onUndoUpload: PropTypes.func,
|
||||||
onUnmount: PropTypes.func,
|
onUnmount: PropTypes.func,
|
||||||
onUpload: PropTypes.func,
|
onUpload: PropTypes.func,
|
||||||
|
anyMedia: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connecting and export.
|
// Connecting and export.
|
||||||
|
|
|
@ -158,7 +158,6 @@ function appendMedia(state, media) {
|
||||||
map.update('media_attachments', list => list.push(media));
|
map.update('media_attachments', list => list.push(media));
|
||||||
map.set('is_uploading', false);
|
map.set('is_uploading', false);
|
||||||
map.set('resetFileKey', Math.floor((Math.random() * 0x10000)));
|
map.set('resetFileKey', Math.floor((Math.random() * 0x10000)));
|
||||||
map.update('text', oldText => `${oldText.trim()} ${media.get('text_url')}`);
|
|
||||||
map.set('focusDate', new Date());
|
map.set('focusDate', new Date());
|
||||||
map.set('idempotencyKey', uuid());
|
map.set('idempotencyKey', uuid());
|
||||||
|
|
||||||
|
@ -169,12 +168,10 @@ function appendMedia(state, media) {
|
||||||
};
|
};
|
||||||
|
|
||||||
function removeMedia(state, mediaId) {
|
function removeMedia(state, mediaId) {
|
||||||
const media = state.get('media_attachments').find(item => item.get('id') === mediaId);
|
|
||||||
const prevSize = state.get('media_attachments').size;
|
const prevSize = state.get('media_attachments').size;
|
||||||
|
|
||||||
return state.withMutations(map => {
|
return state.withMutations(map => {
|
||||||
map.update('media_attachments', list => list.filterNot(item => item.get('id') === mediaId));
|
map.update('media_attachments', list => list.filterNot(item => item.get('id') === mediaId));
|
||||||
map.update('text', text => text.replace(media.get('text_url'), '').trim());
|
|
||||||
map.set('idempotencyKey', uuid());
|
map.set('idempotencyKey', uuid());
|
||||||
|
|
||||||
if (prevSize === 1) {
|
if (prevSize === 1) {
|
||||||
|
|
Loading…
Reference in a new issue