({
chat,
chatMessages,
}: {
chat: ChatResponse;
chatMessages: ChatMessageResponse[];
})
| 28 | import { Id, DocumentCollectionResponse, DocumentResponse, DocumentToCollectionResponse } from "@repo/core"; |
| 29 | |
| 30 | export function ChatWithDocs({ |
| 31 | chat, |
| 32 | chatMessages, |
| 33 | }: { |
| 34 | chat: ChatResponse; |
| 35 | chatMessages: ChatMessageResponse[]; |
| 36 | }) { |
| 37 | const [previewDocumentId, setPreviewDocumentId] = useState< |
| 38 | string | undefined |
| 39 | >(); |
| 40 | |
| 41 | // A state that doesn't need to re-render component. So it's never set -- only values are modified on |
| 42 | // appropriate events. |
| 43 | const [documentsCurrentPageIndexMap, _] = useState<Map<string, number>>( |
| 44 | new Map(), |
| 45 | ); |
| 46 | |
| 47 | const pageNavigationPluginInstance = pageNavigationPlugin(); |
| 48 | const { jumpToPage } = pageNavigationPluginInstance; |
| 49 | |
| 50 | const documentCollectionId = Id.from<DocumentCollectionResponse>( |
| 51 | chat.documentCollectionId!, |
| 52 | ); |
| 53 | |
| 54 | // Fetch documents |
| 55 | const { |
| 56 | data: collectionDocumentsResponse, |
| 57 | error: fetchCollectionDocumentsError, |
| 58 | } = useSWR( |
| 59 | getDocumentCollectionDocumentsApiPath({ |
| 60 | documentCollectionId: documentCollectionId, |
| 61 | pagination: { |
| 62 | // TODO: Allow viewing beyond first 1024 docs in a collection! Scaling problem for later |
| 63 | page: 1, |
| 64 | pageSize: 1024, |
| 65 | }, |
| 66 | ordering: { |
| 67 | orderBy: "createdAt", |
| 68 | order: "desc", |
| 69 | }, |
| 70 | }), |
| 71 | createFetcher<DocumentResponse[]>(), |
| 72 | { |
| 73 | revalidateOnFocus: false, |
| 74 | }, |
| 75 | ); |
| 76 | |
| 77 | const shouldFetchDocumentToCollections = collectionDocumentsResponse && collectionDocumentsResponse.response.length > 0; |
| 78 | const { |
| 79 | data: documentToCollectionsResponse, |
| 80 | error: documentToCollectionsFetchError, |
| 81 | } = useSWR( |
| 82 | shouldFetchDocumentToCollections |
| 83 | ? getDocumentToCollections({ |
| 84 | documentCollectionId: documentCollectionId, |
| 85 | documentIds: collectionDocumentsResponse!.response.map(d => Id.from(d.id)), |
| 86 | }) |
| 87 | : null, |
nothing calls this directly
no test coverage detected