mirror of
https://github.com/langgenius/dify.git
synced 2026-04-23 12:16:11 +08:00
refactor(web): use skipToken for optional query inputs
This commit is contained in:
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
@ -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,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user