just yeet declaration for now
This commit is contained in:
@@ -1,12 +1,18 @@
|
|||||||
import {Platform, View} from 'react-native'
|
import {Platform, View} from 'react-native'
|
||||||
import {Image} from 'expo-image'
|
import {Image} from 'expo-image'
|
||||||
import {type AppBskyActorDefs} from '@atproto/api'
|
import {
|
||||||
|
type AppBskyActorDefs,
|
||||||
|
type AppBskyActorGetProfile,
|
||||||
|
type AtpAgent,
|
||||||
|
} from '@atproto/api'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {useMutation} from '@tanstack/react-query'
|
import {useMutation, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
|
import {until} from '#/lib/async/until'
|
||||||
import {isNetworkError} from '#/lib/strings/errors'
|
import {isNetworkError} from '#/lib/strings/errors'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
|
import {RQKEY} from '#/state/queries/profile'
|
||||||
import {useAgent, useSession} from '#/state/session'
|
import {useAgent, useSession} from '#/state/session'
|
||||||
import {atoms as a, useTheme, web} from '#/alf'
|
import {atoms as a, useTheme, web} from '#/alf'
|
||||||
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
||||||
@@ -79,37 +85,26 @@ function GermSelfButton({did}: {did: string}) {
|
|||||||
const selfExplanationDialogControl = Dialog.useDialogControl()
|
const selfExplanationDialogControl = Dialog.useDialogControl()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
const {mutate, isPending} = useMutation({
|
const {mutate, isPending} = useMutation({
|
||||||
onMutate: async () => {
|
onMutate: async () => {
|
||||||
const res = await agent.com.germnetwork.declaration.get({
|
await agent.com.germnetwork.declaration.delete({
|
||||||
repo: did,
|
repo: did,
|
||||||
rkey: 'self',
|
rkey: 'self',
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!res?.value) {
|
await whenAppViewReady(agent, did, res => !res.data.associated?.germ)
|
||||||
throw new Error('Failed to get self declaration')
|
|
||||||
}
|
|
||||||
|
|
||||||
await agent.com.germnetwork.declaration.put(
|
|
||||||
{
|
|
||||||
repo: did,
|
|
||||||
rkey: 'self',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
...res.value,
|
|
||||||
messageMe: {
|
|
||||||
...res.value.messageMe,
|
|
||||||
// TODO: update types
|
|
||||||
// showButtonTo: 'none',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO: await appview and revalidate profile
|
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
Toast.show(_(msg`Germ DM link removed`))
|
selfExplanationDialogControl.close(() => {
|
||||||
|
Toast.show(
|
||||||
|
_(
|
||||||
|
msg`Germ DM link disconnected. You can reconnect it at any time through the Germ app.`,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
void queryClient.refetchQueries({queryKey: RQKEY(did)})
|
||||||
|
})
|
||||||
},
|
},
|
||||||
onError: error => {
|
onError: error => {
|
||||||
Toast.show(
|
Toast.show(
|
||||||
@@ -169,14 +164,14 @@ function GermSelfButton({did}: {did: string}) {
|
|||||||
</ButtonText>
|
</ButtonText>
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
label={_(msg`Remove Germ DM link`)}
|
label={_(msg`Disconnect Germ DM`)}
|
||||||
size="large"
|
size="large"
|
||||||
color="primary"
|
color="primary"
|
||||||
onPress={() => mutate()}
|
onPress={() => mutate()}
|
||||||
disabled={isPending}>
|
disabled={isPending}>
|
||||||
{isPending && <ButtonIcon icon={Loader} />}
|
{isPending && <ButtonIcon icon={Loader} />}
|
||||||
<ButtonText>
|
<ButtonText>
|
||||||
<Trans>Remove Germ DM link</Trans>
|
<Trans>Disconnect Germ DM</Trans>
|
||||||
</ButtonText>
|
</ButtonText>
|
||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
@@ -222,3 +217,16 @@ function platform() {
|
|||||||
return 'web'
|
return 'web'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function whenAppViewReady(
|
||||||
|
agent: AtpAgent,
|
||||||
|
actor: string,
|
||||||
|
fn: (res: AppBskyActorGetProfile.Response) => boolean,
|
||||||
|
) {
|
||||||
|
await until(
|
||||||
|
5, // 5 tries
|
||||||
|
1e3, // 1s delay between tries
|
||||||
|
fn,
|
||||||
|
() => agent.app.bsky.actor.getProfile({actor}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user