refactor(web): use skipToken for optional query inputs

This commit is contained in:
yyh
2026-02-25 00:55:50 +08:00
parent bad48e5deb
commit d60a43164f
2 changed files with 9 additions and 5 deletions

View File

@ -1,10 +1,11 @@
import { useQuery } from '@tanstack/react-query'
import { skipToken, useQuery } from '@tanstack/react-query'
export function useFetchTextContent(downloadUrl: string | undefined) {
return useQuery({
queryKey: ['fileTextContent', downloadUrl],
queryFn: () => fetch(downloadUrl!).then(r => r.text()),
enabled: !!downloadUrl,
queryFn: downloadUrl
? () => fetch(downloadUrl).then(r => r.text())
: skipToken,
staleTime: Infinity,
})
}

View File

@ -95,11 +95,14 @@ export function useSandboxFilesTree(
appId: string | undefined,
options?: UseSandboxFilesTreeOptions,
) {
const input = appId && (options?.enabled ?? true)
? { params: { appId }, query: { recursive: true } }
: skipToken
const { data, isLoading, error, refetch } = useQuery({
...consoleQuery.sandboxFile.listFiles.queryOptions({
input: { params: { appId: appId! }, query: { recursive: true } },
input,
}),
enabled: !!appId && (options?.enabled ?? true),
refetchInterval: options?.refetchInterval,
})