Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 3,308 Bytes
c750639 |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
import React from "react";
import {
Dialog,
DialogTitle,
DialogContent,
Box,
Typography,
CircularProgress,
IconButton,
Tooltip,
} from "@mui/material";
import DownloadIcon from "@mui/icons-material/Download";
import CloseIcon from "@mui/icons-material/Close";
/**
* Composant pour afficher un document dans une boîte de dialogue
* @param {Object} props - Propriétés du composant
* @returns {JSX.Element} - Dialogue pour visualiser un document
*/
const DocumentViewerDialog = ({
open,
onClose,
document,
content,
isLoading,
isDownloading,
handleDownload,
}) => {
// Déterminer le type de document
const getDocumentType = () => {
if (!document) return "";
if (document.id === "the-bitter-lesson") return "HTML";
if (document.id === "hurricane-faq") return "Markdown";
return "Text";
};
return (
<Dialog
open={open}
onClose={onClose}
maxWidth="md"
fullWidth
aria-labelledby="document-content-dialog-title"
>
<DialogTitle id="document-content-dialog-title">
<Box
sx={{
display: "flex",
justifyContent: "space-between",
alignItems: "flex-start",
}}
>
<Box>
{document && (
<Typography variant="h6" sx={{ fontWeight: 600 }}>
{document.name}
</Typography>
)}
<Typography variant="body2" color="text.secondary">
{document && getDocumentType()}
</Typography>
</Box>
<Box sx={{ display: "flex", gap: 1 }}>
{document && (
<Tooltip title="Download document">
<IconButton
edge="end"
color="inherit"
onClick={() => handleDownload(document)}
disabled={isDownloading}
aria-label="download"
sx={{
color: "text.secondary",
opacity: 0.4,
"&:hover": {
opacity: 0.8,
},
}}
>
{isDownloading ? (
<CircularProgress size={20} />
) : (
<DownloadIcon />
)}
</IconButton>
</Tooltip>
)}
<IconButton
edge="end"
color="inherit"
onClick={onClose}
aria-label="close"
>
<CloseIcon />
</IconButton>
</Box>
</Box>
</DialogTitle>
<DialogContent
dividers
sx={{
padding: 0,
}}
>
{isLoading ? (
<Box sx={{ display: "flex", justifyContent: "center", my: 4 }}>
<CircularProgress />
</Box>
) : (
<Box
sx={{
maxHeight: "60vh",
overflow: "auto",
whiteSpace: "pre-wrap",
fontFamily: "monospace",
fontSize: "0.875rem",
p: 2.5,
}}
>
{content}
</Box>
)}
</DialogContent>
</Dialog>
);
};
export default DocumentViewerDialog;
|