diff options
author | dan <dan.abramov@gmail.com> | 2024-10-29 20:23:02 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-29 20:23:02 +0000 |
commit | 3bf91eb814fbc2206c6d1074794992772f284171 (patch) | |
tree | de7cf80cefe1a543dad6727e2b328f2fdd4daa36 /src | |
parent | 9c27d83d4ba049662a580f4ba63c0832db287710 (diff) | |
download | voidsky-3bf91eb814fbc2206c6d1074794992772f284171.tar.zst |
Disable Post button when empty (#5953)
* Disable Post button when empty * Use regular disabled button * Disable post on video error until cleared
Diffstat (limited to 'src')
-rw-r--r-- | src/view/com/composer/Composer.tsx | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 3eb7fbac6..8fdc62bc3 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -293,13 +293,27 @@ export const ComposePost = ({ return false }, [images, extGifAlt, extGif, requireAltTextEnabled]) + const isEmptyPost = + richtext.text.trim().length === 0 && + images.length === 0 && + !extLink && + !extGif && + !quote && + videoState.status === 'idle' + + const canPost = + graphemeLength <= MAX_GRAPHEME_LENGTH && + !isAltTextRequiredAndMissing && + !isEmptyPost && + videoState.status !== 'error' + const onPressPublish = React.useCallback( async (finishedUploading: boolean) => { - if (isPublishing || graphemeLength > MAX_GRAPHEME_LENGTH) { + if (isPublishing) { return } - if (isAltTextRequiredAndMissing) { + if (!canPost) { return } @@ -313,19 +327,6 @@ export const ComposePost = ({ } setError('') - - if ( - richtext.text.trim().length === 0 && - images.length === 0 && - !extLink && - !extGif && - !quote && - videoState.status === 'idle' - ) { - setError(_(msg`Did you want to say anything?`)) - return - } - setIsPublishing(true) let postUri @@ -410,10 +411,8 @@ export const ComposePost = ({ agent, draft, extLink, - extGif, images, - graphemeLength, - isAltTextRequiredAndMissing, + canPost, isPublishing, langPrefs.postLanguage, onClose, @@ -421,7 +420,6 @@ export const ComposePost = ({ quote, initQuote, replyTo, - richtext.text, setLangPrefs, videoState.asset, videoState.status, @@ -438,11 +436,6 @@ export const ComposePost = ({ } }, [onPressPublish, publishOnUpload, videoState.pendingPublish]) - const canPost = useMemo( - () => graphemeLength <= MAX_GRAPHEME_LENGTH && !isAltTextRequiredAndMissing, - [graphemeLength, isAltTextRequiredAndMissing], - ) - const onEmojiButtonPress = useCallback(() => { openEmojiPicker?.(textInput.current?.getCursorPosition()) }, [openEmojiPicker]) @@ -692,7 +685,7 @@ function ComposerTopBar({ <ActivityIndicator /> </View> </> - ) : canPost ? ( + ) : ( <Button testID="composerPublishBtn" label={isReply ? 'Publish reply' : 'Publish post'} @@ -702,7 +695,7 @@ function ComposerTopBar({ size="small" style={[a.rounded_full, a.py_sm]} onPress={onPublish} - disabled={isPublishQueued}> + disabled={!canPost || isPublishQueued}> <ButtonText style={[a.text_md]}> {isReply ? ( <Trans context="action">Reply</Trans> @@ -711,12 +704,6 @@ function ComposerTopBar({ )} </ButtonText> </Button> - ) : ( - <View style={[styles.postBtn, pal.btn]}> - <Text style={[pal.textLight, s.f16, s.bold]}> - <Trans context="action">Post</Trans> - </Text> - </View> )} </View> {children} |