import baseUrl from "@/services/api/api.config"; import { useTheme } from "@mui/material"; import Grid from "@mui/material/Unstable_Grid2"; import { useEffect, useState } from "react"; import ChatInterface from "../chatInterface"; import ChunkInteface from "../chunkInterface"; import ContextHeader from "../contextHeader"; import ModelSelection from "../modelSelection"; import PreviewChunks from "../previewChunks"; import PreviewDocuments from "../previewDocuments"; import PreviewHeader from "../previewHeader"; import SendMessage from "../sendMessage"; import UploadFile from "../uploadFile"; export default function Body() { const theme = useTheme(); const [messages, setMessages] = useState([]); const [documents, setDocuments] = useState([]); const [chunks, setChunks] = useState([]); const [previewedChunk, setPreviewedChunk] = useState(null); const onSelectedChunk = (chunk) => { if (chunk.documentNumber === previewedChunk) { setPreviewedChunk(null); return; } setPreviewedChunk(chunk.documentNumber); }; const fetchMessages = async () => { const url = `${baseUrl}/query/get_messages`; const response = await fetch(url); const messagesResponse = await response.json(); setMessages(messagesResponse.data); }; const fetchChunks = async () => { const url = `${baseUrl}/document/get_chunks`; const response = await fetch(url); const chunksResponse = await response.json(); if (Object.keys(chunksResponse.data).length === 0) { setDocuments([]); setChunks([]); return; } const documentNames = []; const transformedData = Object.keys(chunksResponse.data).flatMap( (documentKey, index) => { documentNames.push({ id: index + 1, filename: documentKey, }); const documentData = chunksResponse.data[documentKey]; return documentData.map((chunk) => { return { chunkId: chunk.index, documentId: documentKey, text: chunk.text, }; }); } ); setDocuments(documentNames); setChunks(transformedData); }; useEffect(() => { fetchMessages(); fetchChunks(); }, []); return ( <> ); }