Skip to content

Commit

Permalink
invalidate query on success
Browse files Browse the repository at this point in the history
  • Loading branch information
mozzius committed Oct 21, 2024
1 parent 2ee6e69 commit 568b88d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
27 changes: 1 addition & 26 deletions src/screens/Settings/AccountSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import React from 'react'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {NativeStackScreenProps} from '@react-navigation/native-stack'
import {useQueryClient} from '@tanstack/react-query'

import {CommonNavigatorParams} from '#/lib/routes/types'
import {useModalControls} from '#/state/modals'
import {RQKEY as RQKEY_PROFILE} from '#/state/queries/profile'
import {useSession} from '#/state/session'
import {ExportCarDialog} from '#/view/screens/Settings/ExportCarDialog'
import * as SettingsList from '#/screens/Settings/components/SettingsList'
Expand All @@ -32,7 +30,6 @@ export function AccountSettingsScreen({}: Props) {
const t = useTheme()
const {_} = useLingui()
const {currentAccount} = useSession()
const queryClient = useQueryClient()
const {openModal} = useModalControls()
const birthdayControl = useDialogControl()
const changeHandleControl = useDialogControl()
Expand Down Expand Up @@ -115,35 +112,13 @@ export function AccountSettingsScreen({}: Props) {
</SettingsList.ItemText>
<SettingsList.Chevron />
</SettingsList.PressableItem>
<SettingsList.PressableItem
label={_(msg`Handle`)}
accessibilityHint={_(msg`Open change handle dialog`)}
onPress={() =>
openModal({
name: 'change-handle',
onChanged() {
if (currentAccount) {
// refresh my profile
queryClient.invalidateQueries({
queryKey: RQKEY_PROFILE(currentAccount.did),
})
}
},
})
}>
<SettingsList.ItemIcon icon={AtIcon} />
<SettingsList.ItemText>
<Trans>Handle</Trans>
</SettingsList.ItemText>
<SettingsList.Chevron />
</SettingsList.PressableItem>
<SettingsList.PressableItem
label={_(msg`Handle`)}
accessibilityHint={_(msg`Open change handle dialog`)}
onPress={() => changeHandleControl.open()}>
<SettingsList.ItemIcon icon={AtIcon} />
<SettingsList.ItemText>
<Trans>Handle (new)</Trans>
<Trans>Handle</Trans>
</SettingsList.ItemText>
<SettingsList.Chevron />
</SettingsList.PressableItem>
Expand Down
16 changes: 15 additions & 1 deletion src/screens/Settings/components/ChangeHandleDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import Animated, {
import {ComAtprotoServerDescribeServer} from '@atproto/api'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {useMutation} from '@tanstack/react-query'
import {useMutation, useQueryClient} from '@tanstack/react-query'

import {HITSLOP_10} from '#/lib/constants'
import {cleanError} from '#/lib/strings/errors'
import {createFullHandle, validateHandle} from '#/lib/strings/handles'
import {useFetchDid, useUpdateHandleMutation} from '#/state/queries/handle'
import {RQKEY as RQKEY_PROFILE} from '#/state/queries/profile'
import {useServiceQuery} from '#/state/queries/service'
import {useAgent, useSession} from '#/state/session'
import {ErrorScreen} from '#/view/com/util/error/ErrorScreen'
Expand Down Expand Up @@ -145,6 +146,8 @@ function ProvidedHandlePage({
const [subdomain, setSubdomain] = useState('')
const agent = useAgent()
const control = Dialog.useDialogContext()
const {currentAccount} = useSession()
const queryClient = useQueryClient()

const {
mutate: changeHandle,
Expand All @@ -153,6 +156,11 @@ function ProvidedHandlePage({
isSuccess,
} = useUpdateHandleMutation({
onSuccess: () => {
if (currentAccount) {
queryClient.invalidateQueries({
queryKey: RQKEY_PROFILE(currentAccount.did),
})
}
agent.resumeSession(agent.session!).then(() => control.close())
},
})
Expand Down Expand Up @@ -270,6 +278,7 @@ function OwnHandlePage({goToServiceHandle}: {goToServiceHandle: () => void}) {
const agent = useAgent()
const control = Dialog.useDialogContext()
const fetchDid = useFetchDid()
const queryClient = useQueryClient()

const {
mutate: changeHandle,
Expand All @@ -278,6 +287,11 @@ function OwnHandlePage({goToServiceHandle}: {goToServiceHandle: () => void}) {
isSuccess,
} = useUpdateHandleMutation({
onSuccess: () => {
if (currentAccount) {
queryClient.invalidateQueries({
queryKey: RQKEY_PROFILE(currentAccount.did),
})
}
agent.resumeSession(agent.session!).then(() => control.close())
},
})
Expand Down

0 comments on commit 568b88d

Please sign in to comment.