File size: 1,446 Bytes
dcb6c5f
819bacd
 
 
dcb6c5f
819bacd
47b5f0c
819bacd
 
47b5f0c
 
 
 
819bacd
47b5f0c
819bacd
 
47b5f0c
 
 
819bacd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import baseUrl from "@/services/api/api.config";
import { useTheme } from "@emotion/react";
import { Box } from "@mui/material";
import { useEffect } from "react";
import DocumentComponent from "../documentComponent";

export default function PreviewDocuments({ documents, fetchChunks }) {
  const theme = useTheme();

  const deleteDcoument = async (documentName) => {
    const url = `${baseUrl}/document/delete_document/${encodeURIComponent(
      documentName
    )}`;

    const result = await fetch(url, {
      method: "DELETE",
      headers: { "Content-Type": "application/json" },
    });

    await fetchChunks();
  };

  useEffect(() => {}, [documents]);

  return (
    <>
      <Box
        display="flex"
        flexDirection="column"
        flexGrow={1}
        padding={2}
        mb={2}
        style={{
          border: "2px solid black",
          overflow: "hidden",
          overflowY: "scroll",
          borderRadius: "8px",
          border: "1px solid #ccc",
          backgroundColor: theme.palette.background.default,
          height: "40%",
        }}
      >
        {documents.map((document, index) => (
          <DocumentComponent
            key={index}
            documentName={document.filename}
            documentId={`Document_${document.id}`}
            documentNumber={document.id}
            deleteDocument={deleteDcoument}
          ></DocumentComponent>
        ))}
      </Box>
    </>
  );
}