mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-14 16:28:59 +00:00
[Glitch] Show error when submitting empty post rather than failing silently
Port 214d59bd37 to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { throttle } from 'lodash';
|
|||||||
|
|
||||||
import api from 'flavours/glitch/api';
|
import api from 'flavours/glitch/api';
|
||||||
import { browserHistory } from 'flavours/glitch/components/router';
|
import { browserHistory } from 'flavours/glitch/components/router';
|
||||||
|
import { countableText } from 'flavours/glitch/features/compose/util/counter';
|
||||||
import { search as emojiSearch } from 'flavours/glitch/features/emoji/emoji_mart_search_light';
|
import { search as emojiSearch } from 'flavours/glitch/features/emoji/emoji_mart_search_light';
|
||||||
import { tagHistory } from 'flavours/glitch/settings';
|
import { tagHistory } from 'flavours/glitch/settings';
|
||||||
import { recoverHashtags } from 'flavours/glitch/utils/hashtag';
|
import { recoverHashtags } from 'flavours/glitch/utils/hashtag';
|
||||||
@@ -93,6 +94,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) => {
|
||||||
@@ -215,7 +217,15 @@ export function submitCompose(overridePrivacy = null, successCallback = undefine
|
|||||||
const spoilers = getState().getIn(['compose', 'spoiler']) || getState().getIn(['local_settings', 'always_show_spoilers_field']);
|
const spoilers = getState().getIn(['compose', 'spoiler']) || getState().getIn(['local_settings', 'always_show_spoilers_field']);
|
||||||
const spoiler_text = spoilers ? getState().getIn(['compose', 'spoiler_text'], '') : '';
|
const spoiler_text = spoilers ? 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -138,11 +138,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, overridePrivacy = null) => {
|
handleSubmit = (e, overridePrivacy = null) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user