Drill into whenAppViewReady
(cherry picked from commit e290e5be3df509bdd9d0e626a164996c9dee3636)
This commit is contained in:
+33
-11
@@ -4,6 +4,7 @@ import {
|
|||||||
AppBskyGraphGetList,
|
AppBskyGraphGetList,
|
||||||
AppBskyGraphList,
|
AppBskyGraphList,
|
||||||
AtUri,
|
AtUri,
|
||||||
|
BskyAgent,
|
||||||
Facet,
|
Facet,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||||
@@ -85,9 +86,13 @@ export function useListCreateMutation() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// wait for the appview to update
|
// wait for the appview to update
|
||||||
await whenAppViewReady(res.uri, (v: AppBskyGraphGetList.Response) => {
|
await whenAppViewReady(
|
||||||
|
getAgent(),
|
||||||
|
res.uri,
|
||||||
|
(v: AppBskyGraphGetList.Response) => {
|
||||||
return typeof v?.data?.list.uri === 'string'
|
return typeof v?.data?.list.uri === 'string'
|
||||||
})
|
},
|
||||||
|
)
|
||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
@@ -150,12 +155,16 @@ export function useListMetadataMutation() {
|
|||||||
).data
|
).data
|
||||||
|
|
||||||
// wait for the appview to update
|
// wait for the appview to update
|
||||||
await whenAppViewReady(res.uri, (v: AppBskyGraphGetList.Response) => {
|
await whenAppViewReady(
|
||||||
|
getAgent(),
|
||||||
|
res.uri,
|
||||||
|
(v: AppBskyGraphGetList.Response) => {
|
||||||
const list = v.data.list
|
const list = v.data.list
|
||||||
return (
|
return (
|
||||||
list.name === record.name && list.description === record.description
|
list.name === record.name && list.description === record.description
|
||||||
)
|
)
|
||||||
})
|
},
|
||||||
|
)
|
||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
onSuccess(data, variables) {
|
onSuccess(data, variables) {
|
||||||
@@ -220,9 +229,13 @@ export function useListDeleteMutation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// wait for the appview to update
|
// wait for the appview to update
|
||||||
await whenAppViewReady(uri, (v: AppBskyGraphGetList.Response) => {
|
await whenAppViewReady(
|
||||||
|
getAgent(),
|
||||||
|
uri,
|
||||||
|
(v: AppBskyGraphGetList.Response) => {
|
||||||
return !v?.success
|
return !v?.success
|
||||||
})
|
},
|
||||||
|
)
|
||||||
},
|
},
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
invalidateMyLists(queryClient)
|
invalidateMyLists(queryClient)
|
||||||
@@ -244,9 +257,13 @@ export function useListMuteMutation() {
|
|||||||
await getAgent().unmuteModList(uri)
|
await getAgent().unmuteModList(uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
await whenAppViewReady(uri, (v: AppBskyGraphGetList.Response) => {
|
await whenAppViewReady(
|
||||||
|
getAgent(),
|
||||||
|
uri,
|
||||||
|
(v: AppBskyGraphGetList.Response) => {
|
||||||
return Boolean(v?.data.list.viewer?.muted) === mute
|
return Boolean(v?.data.list.viewer?.muted) === mute
|
||||||
})
|
},
|
||||||
|
)
|
||||||
},
|
},
|
||||||
onSuccess(data, variables) {
|
onSuccess(data, variables) {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
@@ -266,11 +283,15 @@ export function useListBlockMutation() {
|
|||||||
await getAgent().unblockModList(uri)
|
await getAgent().unblockModList(uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
await whenAppViewReady(uri, (v: AppBskyGraphGetList.Response) => {
|
await whenAppViewReady(
|
||||||
|
getAgent(),
|
||||||
|
uri,
|
||||||
|
(v: AppBskyGraphGetList.Response) => {
|
||||||
return block
|
return block
|
||||||
? typeof v?.data.list.viewer?.blocked === 'string'
|
? typeof v?.data.list.viewer?.blocked === 'string'
|
||||||
: !v?.data.list.viewer?.blocked
|
: !v?.data.list.viewer?.blocked
|
||||||
})
|
},
|
||||||
|
)
|
||||||
},
|
},
|
||||||
onSuccess(data, variables) {
|
onSuccess(data, variables) {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
@@ -281,6 +302,7 @@ export function useListBlockMutation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function whenAppViewReady(
|
async function whenAppViewReady(
|
||||||
|
agent: BskyAgent,
|
||||||
uri: string,
|
uri: string,
|
||||||
fn: (res: AppBskyGraphGetList.Response) => boolean,
|
fn: (res: AppBskyGraphGetList.Response) => boolean,
|
||||||
) {
|
) {
|
||||||
@@ -289,7 +311,7 @@ async function whenAppViewReady(
|
|||||||
1e3, // 1s delay between tries
|
1e3, // 1s delay between tries
|
||||||
fn,
|
fn,
|
||||||
() =>
|
() =>
|
||||||
getAgent().app.bsky.graph.getList({
|
agent.app.bsky.graph.getList({
|
||||||
list: uri,
|
list: uri,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
AppBskyEmbedRecordWithMedia,
|
AppBskyEmbedRecordWithMedia,
|
||||||
AppBskyFeedDefs,
|
AppBskyFeedDefs,
|
||||||
AtUri,
|
AtUri,
|
||||||
|
BskyAgent,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {
|
import {
|
||||||
QueryClient,
|
QueryClient,
|
||||||
@@ -154,6 +155,7 @@ export function useProfileUpdateMutation() {
|
|||||||
return existing
|
return existing
|
||||||
})
|
})
|
||||||
await whenAppViewReady(
|
await whenAppViewReady(
|
||||||
|
getAgent(),
|
||||||
profile.did,
|
profile.did,
|
||||||
checkCommitted ||
|
checkCommitted ||
|
||||||
(res => {
|
(res => {
|
||||||
@@ -516,6 +518,7 @@ export function precacheThreadPostProfiles(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function whenAppViewReady(
|
async function whenAppViewReady(
|
||||||
|
agent: BskyAgent,
|
||||||
actor: string,
|
actor: string,
|
||||||
fn: (res: AppBskyActorGetProfile.Response) => boolean,
|
fn: (res: AppBskyActorGetProfile.Response) => boolean,
|
||||||
) {
|
) {
|
||||||
@@ -523,7 +526,7 @@ async function whenAppViewReady(
|
|||||||
5, // 5 tries
|
5, // 5 tries
|
||||||
1e3, // 1s delay between tries
|
1e3, // 1s delay between tries
|
||||||
fn,
|
fn,
|
||||||
() => getAgent().app.bsky.actor.getProfile({actor}),
|
() => agent.app.bsky.actor.getProfile({actor}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user