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 diffzio/stable
parent
7543f72b77
commit
3b9c5ceeb3
|
@ -1,4 +1,4 @@
|
||||||
import * as React from 'react'
|
import React from 'react'
|
||||||
import {StyleProp, StyleSheet, View, ViewStyle} from 'react-native'
|
import {StyleProp, StyleSheet, View, ViewStyle} from 'react-native'
|
||||||
import {
|
import {
|
||||||
AppBskyActorDefs,
|
AppBskyActorDefs,
|
||||||
|
@ -7,6 +7,7 @@ import {
|
||||||
ModerationDecision,
|
ModerationDecision,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {Trans} from '@lingui/macro'
|
import {Trans} from '@lingui/macro'
|
||||||
|
import {useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useModerationCauseDescription} from '#/lib/moderation/useModerationCauseDescription'
|
import {useModerationCauseDescription} from '#/lib/moderation/useModerationCauseDescription'
|
||||||
import {useProfileShadow} from '#/state/cache/profile-shadow'
|
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 {sanitizeDisplayName} from 'lib/strings/display-names'
|
||||||
import {sanitizeHandle} from 'lib/strings/handles'
|
import {sanitizeHandle} from 'lib/strings/handles'
|
||||||
import {s} from 'lib/styles'
|
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 {Link} from '../util/Link'
|
||||||
import {Text} from '../util/text/Text'
|
import {Text} from '../util/text/Text'
|
||||||
import {PreviewableUserAvatar} from '../util/UserAvatar'
|
import {PreviewableUserAvatar} from '../util/UserAvatar'
|
||||||
|
@ -47,10 +50,19 @@ export function ProfileCard({
|
||||||
onPress?: () => void
|
onPress?: () => void
|
||||||
style?: StyleProp<ViewStyle>
|
style?: StyleProp<ViewStyle>
|
||||||
}) {
|
}) {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const profile = useProfileShadow(profileUnshadowed)
|
const profile = useProfileShadow(profileUnshadowed)
|
||||||
const moderationOpts = useModerationOpts()
|
const moderationOpts = useModerationOpts()
|
||||||
const isLabeler = profile?.associated?.labeler
|
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) {
|
if (!moderationOpts) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -72,8 +84,8 @@ export function ProfileCard({
|
||||||
]}
|
]}
|
||||||
href={makeProfileLink(profile)}
|
href={makeProfileLink(profile)}
|
||||||
title={profile.handle}
|
title={profile.handle}
|
||||||
onBeforePress={onPress}
|
|
||||||
asAnchor
|
asAnchor
|
||||||
|
onBeforePress={onBeforePress}
|
||||||
anchorNoUnderline>
|
anchorNoUnderline>
|
||||||
<View style={styles.layout}>
|
<View style={styles.layout}>
|
||||||
<View style={styles.layoutAvi}>
|
<View style={styles.layoutAvi}>
|
||||||
|
|
Loading…
Reference in New Issue