WIP
This commit is contained in:
25
frontend/src/hooks/useDocumentDetail.ts
Normal file
25
frontend/src/hooks/useDocumentDetail.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { documentsApi } from '../api/endpoints'
|
||||
import type { DocumentDetailResponse } from '../api/types'
|
||||
|
||||
export const useDocumentDetail = (documentId: string | null) => {
|
||||
const { data, isLoading, error, refetch } = useQuery<DocumentDetailResponse>({
|
||||
queryKey: ['document', documentId],
|
||||
queryFn: () => {
|
||||
if (!documentId) {
|
||||
throw new Error('Document ID is required')
|
||||
}
|
||||
return documentsApi.getDetail(documentId)
|
||||
},
|
||||
enabled: !!documentId,
|
||||
staleTime: 10000,
|
||||
})
|
||||
|
||||
return {
|
||||
document: data || null,
|
||||
annotations: data?.annotations || [],
|
||||
isLoading,
|
||||
error,
|
||||
refetch,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user