Cache DID and profile basic on profile card presses (#3523)

* cache profiles

add onPress back

rm log

cache profile and did when pressing profile card

* minimal diff
zio/stable
Hailey 2024-04-13 17:02:32 -07:00 committed by GitHub
parent 7543f72b77
commit 3b9c5ceeb3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import * as React from 'react'
import React from 'react'
import {StyleProp, StyleSheet, View, ViewStyle} from 'react-native'
import {
AppBskyActorDefs,
@ -7,6 +7,7 @@ import {
ModerationDecision,
} from '@atproto/api'
import {Trans} from '@lingui/macro'
import {useQueryClient} from '@tanstack/react-query'
import {useModerationCauseDescription} from '#/lib/moderation/useModerationCauseDescription'
import {useProfileShadow} from '#/state/cache/profile-shadow'
@ -19,6 +20,8 @@ import {makeProfileLink} from 'lib/routes/links'
import {sanitizeDisplayName} from 'lib/strings/display-names'
import {sanitizeHandle} from 'lib/strings/handles'
import {s} from 'lib/styles'
import {profileBasicQueryKey as RQKEY_PROFILE_BASIC} from 'state/queries/profile'
import {RQKEY as RQKEY_URI} from 'state/queries/resolve-uri'
import {Link} from '../util/Link'
import {Text} from '../util/text/Text'
import {PreviewableUserAvatar} from '../util/UserAvatar'
@ -47,10 +50,19 @@ export function ProfileCard({
onPress?: () => void
style?: StyleProp<ViewStyle>
}) {
const queryClient = useQueryClient()
const pal = usePalette('default')
const profile = useProfileShadow(profileUnshadowed)
const moderationOpts = useModerationOpts()
const isLabeler = profile?.associated?.labeler
const onBeforePress = React.useCallback(() => {
onPress?.()
queryClient.setQueryData(RQKEY_URI(profile.handle), profile.did)
queryClient.setQueryData(RQKEY_PROFILE_BASIC(profile.did), profile)
}, [onPress, profile, queryClient])
if (!moderationOpts) {
return null
}
@ -72,8 +84,8 @@ export function ProfileCard({
]}
href={makeProfileLink(profile)}
title={profile.handle}
onBeforePress={onPress}
asAnchor
onBeforePress={onBeforePress}
anchorNoUnderline>
<View style={styles.layout}>
<View style={styles.layoutAvi}>