Show error when submitting empty post rather than failing silently (#36650)
This commit is contained in:
@@ -5,6 +5,7 @@ import { throttle } from 'lodash';
|
|||||||
|
|
||||||
import api from 'mastodon/api';
|
import api from 'mastodon/api';
|
||||||
import { browserHistory } from 'mastodon/components/router';
|
import { browserHistory } from 'mastodon/components/router';
|
||||||
|
import { countableText } from 'mastodon/features/compose/util/counter';
|
||||||
import { search as emojiSearch } from 'mastodon/features/emoji/emoji_mart_search_light';
|
import { search as emojiSearch } from 'mastodon/features/emoji/emoji_mart_search_light';
|
||||||
import { tagHistory } from 'mastodon/settings';
|
import { tagHistory } from 'mastodon/settings';
|
||||||
|
|
||||||
@@ -88,6 +89,7 @@ const messages = defineMessages({
|
|||||||
open: { id: 'compose.published.open', defaultMessage: 'Open' },
|
open: { id: 'compose.published.open', defaultMessage: 'Open' },
|
||||||
published: { id: 'compose.published.body', defaultMessage: 'Post published.' },
|
published: { id: 'compose.published.body', defaultMessage: 'Post published.' },
|
||||||
saved: { id: 'compose.saved.body', defaultMessage: 'Post saved.' },
|
saved: { id: 'compose.saved.body', defaultMessage: 'Post saved.' },
|
||||||
|
blankPostError: { id: 'compose.error.blank_post', defaultMessage: 'Post can\'t be blank.' },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ensureComposeIsVisible = (getState) => {
|
export const ensureComposeIsVisible = (getState) => {
|
||||||
@@ -197,7 +199,15 @@ export function submitCompose(successCallback) {
|
|||||||
const hasQuote = !!getState().getIn(['compose', 'quoted_status_id']);
|
const hasQuote = !!getState().getIn(['compose', 'quoted_status_id']);
|
||||||
const spoiler_text = getState().getIn(['compose', 'spoiler']) ? getState().getIn(['compose', 'spoiler_text'], '') : '';
|
const spoiler_text = getState().getIn(['compose', 'spoiler']) ? getState().getIn(['compose', 'spoiler_text'], '') : '';
|
||||||
|
|
||||||
if (!(status?.length || media.size !== 0 || (hasQuote && spoiler_text?.length))) {
|
const fulltext = `${spoiler_text ?? ''}${countableText(status ?? '')}`;
|
||||||
|
const hasText = fulltext.trim().length > 0;
|
||||||
|
|
||||||
|
if (!(hasText || media.size !== 0 || (hasQuote && spoiler_text?.length))) {
|
||||||
|
dispatch(showAlert({
|
||||||
|
message: messages.blankPostError,
|
||||||
|
}));
|
||||||
|
dispatch(focusCompose());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,11 +123,10 @@ class ComposeForm extends ImmutablePureComponent {
|
|||||||
};
|
};
|
||||||
|
|
||||||
canSubmit = () => {
|
canSubmit = () => {
|
||||||
const { isSubmitting, isChangingUpload, isUploading, anyMedia, maxChars } = this.props;
|
const { isSubmitting, isChangingUpload, isUploading, maxChars } = this.props;
|
||||||
const fulltext = this.getFulltextForCharacterCounting();
|
const fulltext = this.getFulltextForCharacterCounting();
|
||||||
const isOnlyWhitespace = fulltext.length !== 0 && fulltext.trim().length === 0;
|
|
||||||
|
|
||||||
return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxChars || (isOnlyWhitespace && !anyMedia));
|
return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxChars);
|
||||||
};
|
};
|
||||||
|
|
||||||
handleSubmit = (e) => {
|
handleSubmit = (e) => {
|
||||||
|
|||||||
@@ -194,6 +194,7 @@
|
|||||||
"community.column_settings.local_only": "Local only",
|
"community.column_settings.local_only": "Local only",
|
||||||
"community.column_settings.media_only": "Media Only",
|
"community.column_settings.media_only": "Media Only",
|
||||||
"community.column_settings.remote_only": "Remote only",
|
"community.column_settings.remote_only": "Remote only",
|
||||||
|
"compose.error.blank_post": "Post can't be blank.",
|
||||||
"compose.language.change": "Change language",
|
"compose.language.change": "Change language",
|
||||||
"compose.language.search": "Search languages...",
|
"compose.language.search": "Search languages...",
|
||||||
"compose.published.body": "Post published.",
|
"compose.published.body": "Post published.",
|
||||||
|
|||||||
Reference in New Issue
Block a user