fix: add type safety to profile follows cache update
Replace any types with proper InfiniteData<AppBskyGraphGetFollows.OutputSchema> typing for the optimistic cache update when following/unfollowing profiles. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,12 +4,14 @@ import {
|
|||||||
type AppBskyActorGetProfile,
|
type AppBskyActorGetProfile,
|
||||||
type AppBskyActorGetProfiles,
|
type AppBskyActorGetProfiles,
|
||||||
type AppBskyActorProfile,
|
type AppBskyActorProfile,
|
||||||
|
type AppBskyGraphGetFollows,
|
||||||
AtUri,
|
AtUri,
|
||||||
type BskyAgent,
|
type BskyAgent,
|
||||||
type ComAtprotoRepoUploadBlob,
|
type ComAtprotoRepoUploadBlob,
|
||||||
type Un$Typed,
|
type Un$Typed,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {
|
import {
|
||||||
|
type InfiniteData,
|
||||||
keepPreviousData,
|
keepPreviousData,
|
||||||
type QueryClient,
|
type QueryClient,
|
||||||
useMutation,
|
useMutation,
|
||||||
@@ -287,14 +289,16 @@ export function useProfileFollowMutationQueue(
|
|||||||
|
|
||||||
// Optimistically update profile follows cache for avatar displays
|
// Optimistically update profile follows cache for avatar displays
|
||||||
if (currentAccount?.did) {
|
if (currentAccount?.did) {
|
||||||
queryClient.setQueryData(
|
type FollowsQueryData =
|
||||||
|
InfiniteData<AppBskyGraphGetFollows.OutputSchema>
|
||||||
|
queryClient.setQueryData<FollowsQueryData>(
|
||||||
PROFILE_FOLLOWS_RQKEY(currentAccount.did),
|
PROFILE_FOLLOWS_RQKEY(currentAccount.did),
|
||||||
(old: any) => {
|
old => {
|
||||||
if (!old?.pages?.[0]) return old
|
if (!old?.pages?.[0]) return old
|
||||||
if (finalFollowingUri) {
|
if (finalFollowingUri) {
|
||||||
// Add the followed profile to the beginning
|
// Add the followed profile to the beginning
|
||||||
const alreadyExists = old.pages[0].follows.some(
|
const alreadyExists = old.pages[0].follows.some(
|
||||||
(f: any) => f.did === profile.did,
|
f => f.did === profile.did,
|
||||||
)
|
)
|
||||||
if (alreadyExists) return old
|
if (alreadyExists) return old
|
||||||
return {
|
return {
|
||||||
@@ -302,7 +306,10 @@ export function useProfileFollowMutationQueue(
|
|||||||
pages: [
|
pages: [
|
||||||
{
|
{
|
||||||
...old.pages[0],
|
...old.pages[0],
|
||||||
follows: [profile, ...old.pages[0].follows],
|
follows: [
|
||||||
|
profile as AppBskyActorDefs.ProfileView,
|
||||||
|
...old.pages[0].follows,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
...old.pages.slice(1),
|
...old.pages.slice(1),
|
||||||
],
|
],
|
||||||
@@ -311,11 +318,9 @@ export function useProfileFollowMutationQueue(
|
|||||||
// Remove the unfollowed profile
|
// Remove the unfollowed profile
|
||||||
return {
|
return {
|
||||||
...old,
|
...old,
|
||||||
pages: old.pages.map((page: any) => ({
|
pages: old.pages.map(page => ({
|
||||||
...page,
|
...page,
|
||||||
follows: page.follows.filter(
|
follows: page.follows.filter(f => f.did !== profile.did),
|
||||||
(f: any) => f.did !== profile.did,
|
|
||||||
),
|
|
||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user