refactor: optimize swr data refresh paths

This commit is contained in:
Tunglies
2026-06-28 19:42:21 +08:00
parent e71e701fd0
commit b9da0875cd
16 changed files with 153 additions and 162 deletions
+10 -7
View File
@@ -7,8 +7,12 @@ import {
getRuntimeConfig,
patchClashConfig,
} from '@/services/cmds'
import { useQuery } from '@/services/query-client'
import { queryClient } from '@/services/query-client'
import {
getCacheData,
revalidateQuery,
setCacheData,
useQuery,
} from '@/services/query-client'
type MutateClashUpdater =
| ((old: IConfigData | undefined) => IConfigData | undefined)
@@ -90,9 +94,9 @@ export const useClash = () => {
}
const next =
typeof updater === 'function'
? updater(queryClient.getQueryData<IConfigData>(['getRuntimeConfig']))
? updater(getCacheData<IConfigData>(['getRuntimeConfig']))
: updater
queryClient.setQueryData(['getRuntimeConfig'], next)
setCacheData(['getRuntimeConfig'], next)
if (revalidate !== false) {
return refetch()
}
@@ -130,11 +134,10 @@ export const useClashInfo = () => {
await patchClashConfig(patch)
mutateInfo()
queryClient.invalidateQueries({ queryKey: ['getClashConfig'] })
revalidateQuery(['getClashConfig'])
})
const invalidateClashConfig = () =>
queryClient.invalidateQueries({ queryKey: ['getClashConfig'] })
const invalidateClashConfig = () => revalidateQuery(['getClashConfig'])
return {
clashInfo,