prefetch subject profile
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
useListMembershipAddMutation,
|
||||
useListMembershipRemoveMutation,
|
||||
} from '#/state/queries/list-memberships'
|
||||
import {useProfileQuery} from '#/state/queries/profile'
|
||||
import {atoms as a, native, platform, useTheme} from '#/alf'
|
||||
import {AvatarStack} from '#/components/AvatarStack'
|
||||
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
||||
@@ -129,6 +130,7 @@ function StarterPackList({
|
||||
}) {
|
||||
const control = Dialog.useDialogContext()
|
||||
const {_} = useLingui()
|
||||
const {data: subject} = useProfileQuery({did: targetDid})
|
||||
|
||||
const {
|
||||
data,
|
||||
@@ -153,9 +155,13 @@ function StarterPackList({
|
||||
|
||||
const renderItem = useCallback(
|
||||
({item}: {item: StarterPackWithMembership}) => (
|
||||
<StarterPackItem starterPackWithMembership={item} targetDid={targetDid} />
|
||||
<StarterPackItem
|
||||
starterPackWithMembership={item}
|
||||
targetDid={targetDid}
|
||||
subject={subject}
|
||||
/>
|
||||
),
|
||||
[targetDid],
|
||||
[targetDid, subject],
|
||||
)
|
||||
|
||||
const onClose = useCallback(() => {
|
||||
@@ -244,9 +250,11 @@ function StarterPackList({
|
||||
function StarterPackItem({
|
||||
starterPackWithMembership,
|
||||
targetDid,
|
||||
subject,
|
||||
}: {
|
||||
starterPackWithMembership: StarterPackWithMembership
|
||||
targetDid: string
|
||||
subject: bsky.profile.AnyProfileView
|
||||
}) {
|
||||
const t = useTheme()
|
||||
const ax = useAnalytics()
|
||||
@@ -257,6 +265,7 @@ function StarterPackItem({
|
||||
|
||||
const {mutate: addMembership, isPending: isPendingAdd} =
|
||||
useListMembershipAddMutation({
|
||||
subject,
|
||||
onSuccess: () => {
|
||||
Toast.show(_(msg`Added to starter pack`))
|
||||
},
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
import {STALE} from '#/state/queries'
|
||||
import {RQKEY as LIST_MEMBERS_RQKEY} from '#/state/queries/list-members'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
import {RQKEY_WITH_MEMBERSHIP as STARTER_PACKS_WITH_MEMBERSHIPS_RKEY} from './actor-starter-packs'
|
||||
|
||||
// sanity limit is SANITY_PAGE_LIMIT*PAGE_SIZE total records
|
||||
@@ -101,9 +102,14 @@ export function getMembership(
|
||||
}
|
||||
|
||||
export function useListMembershipAddMutation({
|
||||
subject,
|
||||
onSuccess,
|
||||
onError,
|
||||
}: {
|
||||
/**
|
||||
* Needed for optimistic update of starter pack query
|
||||
*/
|
||||
subject?: bsky.profile.AnyProfileView
|
||||
onSuccess?: (data: {uri: string; cid: string}) => void
|
||||
onError?: (error: Error) => void
|
||||
} = {}) {
|
||||
@@ -133,7 +139,7 @@ export function useListMembershipAddMutation({
|
||||
// -prf
|
||||
return res
|
||||
},
|
||||
onSuccess: async (data, variables) => {
|
||||
onSuccess: (data, variables) => {
|
||||
// manually update the cache; a refetch is too expensive
|
||||
let memberships = queryClient.getQueryData<ListMembersip[]>(RQKEY())
|
||||
if (memberships) {
|
||||
@@ -163,10 +169,6 @@ export function useListMembershipAddMutation({
|
||||
}, 1e3)
|
||||
|
||||
// update WITH_MEMBERSHIPS query
|
||||
const subject = await agent
|
||||
.getProfile({actor: variables.actorDid})
|
||||
.then(res => res.data)
|
||||
.catch(() => undefined)
|
||||
|
||||
if (subject) {
|
||||
queryClient.setQueryData<
|
||||
|
||||
Reference in New Issue
Block a user