fix native post meta (#4530)

zio/stable
Hailey 2024-06-16 02:23:48 -07:00 committed by GitHub
parent eaef1446f2
commit d0bb97e8a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 47 deletions

View File

@ -51,10 +51,23 @@ const floatingMiddlewares = [
] ]
export function ProfileHoverCard(props: ProfileHoverCardProps) { export function ProfileHoverCard(props: ProfileHoverCardProps) {
const prefetchProfileQuery = usePrefetchProfileQuery()
const prefetchedProfile = React.useRef(false)
const onPointerMove = () => {
if (!prefetchedProfile.current) {
prefetchedProfile.current = true
prefetchProfileQuery(props.did)
}
}
if (props.disable || isTouchDevice) { if (props.disable || isTouchDevice) {
return props.children return props.children
} else { } else {
return <ProfileHoverCardInner {...props} /> return (
<View onPointerMove={onPointerMove}>
<ProfileHoverCardInner {...props} />
</View>
)
} }
} }

View File

@ -3,15 +3,14 @@ import {StyleProp, StyleSheet, TextStyle, View, ViewStyle} from 'react-native'
import {AppBskyActorDefs, ModerationDecision, ModerationUI} from '@atproto/api' import {AppBskyActorDefs, ModerationDecision, ModerationUI} from '@atproto/api'
import {useQueryClient} from '@tanstack/react-query' import {useQueryClient} from '@tanstack/react-query'
import {precacheProfile, usePrefetchProfileQuery} from '#/state/queries/profile' import {precacheProfile} from '#/state/queries/profile'
import {usePalette} from 'lib/hooks/usePalette' import {usePalette} from 'lib/hooks/usePalette'
import {makeProfileLink} from 'lib/routes/links' import {makeProfileLink} from 'lib/routes/links'
import {sanitizeDisplayName} from 'lib/strings/display-names' import {sanitizeDisplayName} from 'lib/strings/display-names'
import {sanitizeHandle} from 'lib/strings/handles' import {sanitizeHandle} from 'lib/strings/handles'
import {niceDate} from 'lib/strings/time' import {niceDate} from 'lib/strings/time'
import {TypographyVariant} from 'lib/ThemeContext' import {TypographyVariant} from 'lib/ThemeContext'
import {isAndroid, isWeb} from 'platform/detection' import {isAndroid} from 'platform/detection'
import {atoms as a} from '#/alf'
import {ProfileHoverCard} from '#/components/ProfileHoverCard' import {ProfileHoverCard} from '#/components/ProfileHoverCard'
import {TextLinkOnWebOnly} from './Link' import {TextLinkOnWebOnly} from './Link'
import {Text} from './text/Text' import {Text} from './text/Text'
@ -37,17 +36,7 @@ let PostMeta = (opts: PostMetaOpts): React.ReactNode => {
const pal = usePalette('default') const pal = usePalette('default')
const displayName = opts.author.displayName || opts.author.handle const displayName = opts.author.displayName || opts.author.handle
const handle = opts.author.handle const handle = opts.author.handle
const prefetchProfileQuery = usePrefetchProfileQuery()
const profileLink = makeProfileLink(opts.author) const profileLink = makeProfileLink(opts.author)
const prefetchedProfile = React.useRef(false)
const onPointerMove = React.useCallback(() => {
if (!prefetchedProfile.current) {
prefetchedProfile.current = true
prefetchProfileQuery(opts.author.did)
}
}, [opts.author.did, prefetchProfileQuery])
const queryClient = useQueryClient() const queryClient = useQueryClient()
const onOpenAuthor = opts.onOpenAuthor const onOpenAuthor = opts.onOpenAuthor
const onBeforePressAuthor = useCallback(() => { const onBeforePressAuthor = useCallback(() => {
@ -71,39 +60,35 @@ let PostMeta = (opts: PostMetaOpts): React.ReactNode => {
</View> </View>
)} )}
<ProfileHoverCard inline did={opts.author.did}> <ProfileHoverCard inline did={opts.author.did}>
<View <Text
onPointerMove={isWeb ? onPointerMove : undefined} numberOfLines={1}
style={[a.flex_1]}> style={[styles.maxWidth, pal.textLight, opts.displayNameStyle]}>
<Text <TextLinkOnWebOnly
numberOfLines={1} type={opts.displayNameType || 'lg-bold'}
style={[styles.maxWidth, pal.textLight, opts.displayNameStyle]}> style={[pal.text]}
<TextLinkOnWebOnly lineHeight={1.2}
type={opts.displayNameType || 'lg-bold'} disableMismatchWarning
style={[pal.text]} text={
lineHeight={1.2} <>
disableMismatchWarning {sanitizeDisplayName(
text={ displayName,
<> opts.moderation?.ui('displayName'),
{sanitizeDisplayName( )}
displayName, </>
opts.moderation?.ui('displayName'), }
)} href={profileLink}
</> onBeforePress={onBeforePressAuthor}
} />
href={profileLink} <TextLinkOnWebOnly
onBeforePress={onBeforePressAuthor} type="md"
/> disableMismatchWarning
<TextLinkOnWebOnly style={[pal.textLight, {flexShrink: 4}]}
type="md" text={'\xa0' + sanitizeHandle(handle, '@')}
disableMismatchWarning href={profileLink}
style={[pal.textLight, {flexShrink: 4}]} onBeforePress={onBeforePressAuthor}
text={'\xa0' + sanitizeHandle(handle, '@')} anchorNoUnderline
href={profileLink} />
onBeforePress={onBeforePressAuthor} </Text>
anchorNoUnderline
/>
</Text>
</View>
</ProfileHoverCard> </ProfileHoverCard>
{!isAndroid && ( {!isAndroid && (
<Text <Text