convo button skeleton (#4115)

zio/stable
Samuel Newman 2024-05-20 19:44:50 +01:00 committed by GitHub
parent 492216a584
commit cc7a0da1a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 50 additions and 18 deletions

View File

@ -1,4 +1,5 @@
import React from 'react' import React from 'react'
import {View} from 'react-native'
import {AppBskyActorDefs} from '@atproto/api' import {AppBskyActorDefs} from '@atproto/api'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
@ -7,6 +8,7 @@ import {useMaybeConvoForUser} from '#/state/queries/messages/get-convo-for-membe
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {Message_Stroke2_Corner0_Rounded as Message} from '../icons/Message' import {Message_Stroke2_Corner0_Rounded as Message} from '../icons/Message'
import {Link} from '../Link' import {Link} from '../Link'
import {canBeMessaged} from './util'
export function MessageProfileButton({ export function MessageProfileButton({
profile, profile,
@ -16,24 +18,54 @@ export function MessageProfileButton({
const {_} = useLingui() const {_} = useLingui()
const t = useTheme() const t = useTheme()
const {data: convoId} = useMaybeConvoForUser(profile.did) const {data: convoId, isPending} = useMaybeConvoForUser(profile.did)
if (!convoId) return null if (isPending) {
// show pending state based on declaration
if (canBeMessaged(profile)) {
return (
<View
testID="dmBtnLoading"
aria-hidden={true}
style={[
a.justify_center,
a.align_center,
t.atoms.bg_contrast_25,
a.rounded_full,
{width: 36, height: 36},
]}>
<Message
style={[
t.atoms.text,
{marginLeft: 1, marginBottom: 1, opacity: 0.3},
]}
size="md"
/>
</View>
)
} else {
return null
}
}
return ( if (convoId) {
<Link return (
testID="dmBtn" <Link
size="small" testID="dmBtn"
color="secondary" size="small"
variant="solid" color="secondary"
shape="round" variant="solid"
label={_(msg`Message ${profile.handle}`)} shape="round"
to={`/messages/${convoId}`} label={_(msg`Message ${profile.handle}`)}
style={[a.justify_center, {width: 36, height: 36}]}> to={`/messages/${convoId}`}
<Message style={[a.justify_center, {width: 36, height: 36}]}>
style={[t.atoms.text, {marginLeft: 1, marginBottom: 1}]} <Message
size="md" style={[t.atoms.text, {marginLeft: 1, marginBottom: 1}]}
/> size="md"
</Link> />
) </Link>
)
} else {
return null
}
} }