mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 01:48:04 +08:00
refactor: replace Container with List, update DatasetCard z-index, and implement useDatasetList for data fetching
This commit is contained in:
32
web/service/knowledge/use-dataset.ts
Normal file
32
web/service/knowledge/use-dataset.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { useInfiniteQuery } from '@tanstack/react-query'
|
||||
import type { DataSetListResponse, DatasetListRequest } from '@/models/datasets'
|
||||
import { get } from '../base'
|
||||
import { useReset } from '../use-base'
|
||||
import qs from 'qs'
|
||||
|
||||
const NAME_SPACE = 'dataset'
|
||||
|
||||
const DatasetListKey = [NAME_SPACE, 'list']
|
||||
|
||||
export const useDatasetList = (params: DatasetListRequest) => {
|
||||
const { initialPage, tag_ids, limit, include_all, keyword } = params
|
||||
return useInfiniteQuery({
|
||||
queryKey: [...DatasetListKey, initialPage, tag_ids, limit, include_all, keyword],
|
||||
queryFn: ({ pageParam = 1 }) => {
|
||||
const urlParams = qs.stringify({
|
||||
tag_ids,
|
||||
limit,
|
||||
include_all,
|
||||
keyword,
|
||||
page: pageParam,
|
||||
}, { indices: false })
|
||||
return get<DataSetListResponse>(`/datasets?${urlParams}`)
|
||||
},
|
||||
getNextPageParam: lastPage => lastPage.has_more ? lastPage.page + 1 : null,
|
||||
initialPageParam: initialPage,
|
||||
})
|
||||
}
|
||||
|
||||
export const useResetDatasetList = () => {
|
||||
return useReset([...DatasetListKey])
|
||||
}
|
||||
Reference in New Issue
Block a user