about summary refs log tree commit diff
path: root/src/view/com/profile/ProfileCard.tsx
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-04-13 17:02:32 -0700
committerGitHub <noreply@github.com>2024-04-13 17:02:32 -0700
commit3b9c5ceeb3c5944e5de7b3fdec9be83d2a3da2f1 (patch)
treef714b9826d19742989348e47b961adfc5759d407 /src/view/com/profile/ProfileCard.tsx
parent7543f72b778804b5293bb04505da01e8cc2bace1 (diff)
downloadvoidsky-3b9c5ceeb3c5944e5de7b3fdec9be83d2a3da2f1.tar.zst
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
Diffstat (limited to 'src/view/com/profile/ProfileCard.tsx')
-rw-r--r--src/view/com/profile/ProfileCard.tsx16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/view/com/profile/ProfileCard.tsx b/src/view/com/profile/ProfileCard.tsx
index e6df5f6d0..b52573a01 100644
--- a/src/view/com/profile/ProfileCard.tsx
+++ b/src/view/com/profile/ProfileCard.tsx
@@ -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}>