Disable Post button when empty (#5953)

* Disable Post button when empty

* Use regular disabled button

* Disable post on video error until cleared
This commit is contained in:
dan
2024-10-29 20:23:02 +00:00
committed by GitHub
parent 9c27d83d4b
commit 3bf91eb814
+19 -32
View File
@@ -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}