import { IconButton, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Tooltip } from "@mui/material"; import { useCallback, useContext } from "react"; import { useTranslation } from "react-i18next"; import { sizeToString } from "../../../../util"; import { NoWrapCell, NoWrapTableCell, NoWrapTypography, StyledTableContainerPaper, } from "../../../Common/StyledComponents"; import TimeBadge from "../../../Common/TimeBadge"; import Delete from "../../../Icons/Delete"; import Open from "../../../Icons/Open"; import { FileDialogContext } from "./FileDialog"; const FileDirectLinks = () => { const { t } = useTranslation("dashboard"); const { setFile, values } = useContext(FileDialogContext); const handleDelete = (id: number) => { setFile((prev) => ({ ...prev, edges: { ...prev.edges, direct_links: prev.edges?.direct_links?.filter((link) => link.id !== id), }, })); }; const handleOpen = (id: number) => { window.open(values?.direct_link_map?.[id] ?? "", "_blank"); }; const linkId = useCallback( (id: number) => { const url = new URL(values?.direct_link_map?.[id] ?? ""); return url.pathname; }, [values?.direct_link_map], ); return ( {t("group.#")} {t("file.name")} {t("file.downloads")} {t("file.speed")} {t("file.directLinkId")} {t("file.createdAt")} {values?.edges?.direct_links?.map((option, index) => { const lid = linkId(option.id); return ( {option.id} {option.name ?? ""} {option.downloads ?? 0} {option.speed ? `${sizeToString(option.speed)}/s` : "-"} {lid} handleOpen(option.id)}> handleDelete(option.id)}> ); })} {!values?.edges?.direct_links?.length && ( {t("file.noRecords")} )}
); }; export default FileDirectLinks;