migrate the pinned post and verification cache profile reads to the appview client
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,14 +5,15 @@ import {useMutation, useQueryClient} from '@tanstack/react-query'
|
|||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed'
|
import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed'
|
||||||
import * as Toast from '#/components/Toast'
|
import * as Toast from '#/components/Toast'
|
||||||
|
import {app} from '#/lexicons'
|
||||||
import {updatePostShadow} from '../cache/post-shadow'
|
import {updatePostShadow} from '../cache/post-shadow'
|
||||||
import {useAgent, useSession} from '../session'
|
import {useAppviewClient, useSession} from '../session'
|
||||||
import {useProfileUpdateMutation} from './profile'
|
import {useProfileUpdateMutation} from './profile'
|
||||||
|
|
||||||
export function usePinnedPostMutation() {
|
export function usePinnedPostMutation() {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const agent = useAgent()
|
const client = useAppviewClient()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const {mutateAsync: profileUpdateMutate} = useProfileUpdateMutation()
|
const {mutateAsync: profileUpdateMutate} = useProfileUpdateMutation()
|
||||||
|
|
||||||
@@ -33,8 +34,9 @@ export function usePinnedPostMutation() {
|
|||||||
|
|
||||||
// get the currently pinned post so we can optimistically remove the pin from it
|
// get the currently pinned post so we can optimistically remove the pin from it
|
||||||
if (!currentAccount) throw new Error('Not signed in')
|
if (!currentAccount) throw new Error('Not signed in')
|
||||||
const {data: profile} = await agent.getProfile({
|
const profile = await client.call(app.bsky.actor.getProfile, {
|
||||||
actor: currentAccount.did,
|
actor:
|
||||||
|
currentAccount.did as app.bsky.actor.getProfile.$Params['actor'],
|
||||||
})
|
})
|
||||||
prevPinnedPost = profile.pinnedPost?.uri
|
prevPinnedPost = profile.pinnedPost?.uri
|
||||||
if (prevPinnedPost && prevPinnedPost !== postUri) {
|
if (prevPinnedPost && prevPinnedPost !== postUri) {
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import {useQueryClient} from '@tanstack/react-query'
|
|||||||
|
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {updateProfileShadow} from '#/state/cache/profile-shadow'
|
import {updateProfileShadow} from '#/state/cache/profile-shadow'
|
||||||
import {useAgent} from '#/state/session'
|
import {useAppviewClient} from '#/state/session'
|
||||||
|
import {app} from '#/lexicons'
|
||||||
import type * as bsky from '#/types/bsky'
|
import type * as bsky from '#/types/bsky'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,13 +14,14 @@ import type * as bsky from '#/types/bsky'
|
|||||||
*/
|
*/
|
||||||
export function useUpdateProfileVerificationCache() {
|
export function useUpdateProfileVerificationCache() {
|
||||||
const qc = useQueryClient()
|
const qc = useQueryClient()
|
||||||
const agent = useAgent()
|
const client = useAppviewClient()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
async ({profile}: {profile: bsky.profile.AnyProfileView}) => {
|
async ({profile}: {profile: bsky.profile.AnyProfileView}) => {
|
||||||
try {
|
try {
|
||||||
const {data: updated} = await agent.getProfile({
|
const updated = await client.call(app.bsky.actor.getProfile, {
|
||||||
actor: profile.did ?? '',
|
actor: (profile.did ??
|
||||||
|
'') as app.bsky.actor.getProfile.$Params['actor'],
|
||||||
})
|
})
|
||||||
updateProfileShadow(qc, profile.did, {
|
updateProfileShadow(qc, profile.did, {
|
||||||
verification: updated.verification,
|
verification: updated.verification,
|
||||||
@@ -30,6 +32,6 @@ export function useUpdateProfileVerificationCache() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[agent, qc],
|
[client, qc],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user