2025-05-16 16:32:25 +08:00
|
|
|
import { useInfiniteQuery, useQuery } from '@tanstack/react-query'
|
|
|
|
import type { DataSet, DataSetListResponse, DatasetListRequest, RelatedAppResponse } from '@/models/datasets'
|
2025-05-16 10:50:31 +08:00
|
|
|
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])
|
|
|
|
}
|
2025-05-16 16:32:25 +08:00
|
|
|
|
|
|
|
export const useDatasetDetail = (datasetId: string) => {
|
|
|
|
return useQuery({
|
|
|
|
queryKey: [NAME_SPACE, 'detail', datasetId],
|
|
|
|
queryFn: () => get<DataSet>(`/datasets/${datasetId}`),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useDatasetRelatedApps = (datasetId: string) => {
|
|
|
|
return useQuery({
|
|
|
|
queryKey: [NAME_SPACE, 'related-apps', datasetId],
|
2025-05-16 16:49:43 +08:00
|
|
|
queryFn: () => get<RelatedAppResponse>(`/datasets/${datasetId}/related-apps`),
|
2025-05-16 16:32:25 +08:00
|
|
|
})
|
|
|
|
}
|
2025-05-22 14:49:40 +08:00
|
|
|
|
|
|
|
type NotionPagePreviewRequest = {
|
|
|
|
workspaceID: string
|
|
|
|
pageID: string
|
|
|
|
pageType: string
|
|
|
|
}
|
|
|
|
|
|
|
|
type NotionPagePreviewResponse = {
|
|
|
|
content: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export const usePreviewNotionPage = (params: NotionPagePreviewRequest) => {
|
|
|
|
const { workspaceID, pageID, pageType } = params
|
|
|
|
return useQuery({
|
|
|
|
queryKey: [NAME_SPACE, 'preview-notion-page'],
|
|
|
|
queryFn: () => get<NotionPagePreviewResponse>(`notion/workspaces/${workspaceID}/pages/${pageID}/${pageType}/preview`),
|
|
|
|
enabled: !!workspaceID && !!pageID && !!pageType,
|
|
|
|
})
|
|
|
|
}
|