Debian Codegraph @

web/src/components/AttachmentIcon.jsx

raw
1 import * as React from "react";
2 import { Box, Link } from "@mui/material";
3 import { useTranslation } from "react-i18next";
4 import fileDocument from "../img/file-document.svg";
5 import fileImage from "../img/file-image.svg";
6 import fileVideo from "../img/file-video.svg";
7 import fileAudio from "../img/file-audio.svg";
8 import fileApp from "../img/file-app.svg";
9
10 const AttachmentIcon = (props) => {
11 const { t } = useTranslation();
12 const { type } = props;
13 let imageFile;
14 let imageLabel;
15 if (!type) {
16 imageFile = fileDocument;
17 imageLabel = t("notifications_attachment_file_image");
18 } else if (type.startsWith("image/")) {
19 imageFile = fileImage;
20 imageLabel = t("notifications_attachment_file_video");
21 } else if (type.startsWith("video/")) {
22 imageFile = fileVideo;
23 imageLabel = t("notifications_attachment_file_video");
24 } else if (type.startsWith("audio/")) {
25 imageFile = fileAudio;
26 imageLabel = t("notifications_attachment_file_audio");
27 } else if (type === "application/vnd.android.package-archive") {
28 imageFile = fileApp;
29 imageLabel = t("notifications_attachment_file_app");
30 } else {
31 imageFile = fileDocument;
32 imageLabel = t("notifications_attachment_file_document");
33 }
34 const icon = (
35 <Box
36 component="img"
37 src={imageFile}
38 alt={imageLabel}
39 loading="lazy"
40 sx={{
41 width: "28px",
42 height: "28px",
43 }}
44 />
45 );
46 if (!props.href) {
47 return icon;
48 }
49 return (
50 <Link href={props.href} target="_blank" rel="noopener noreferrer">
51 {icon}
52 </Link>
53 );
54 };
55
56 export default AttachmentIcon;