import clsx from "clsx"; import React from "react"; import { Resource } from "@/types/proto/api/v1/resource_service"; import { getResourceType, getResourceUrl } from "@/utils/resource"; import Icon from "./Icon"; import showPreviewImageDialog from "./PreviewImageDialog"; import SquareDiv from "./kit/SquareDiv"; interface Props { resource: Resource; className?: string; strokeWidth?: number; } const ResourceIcon = (props: Props) => { const { resource } = props; const resourceType = getResourceType(resource); const resourceUrl = getResourceUrl(resource); const className = clsx("w-full h-auto", props.className); const strokeWidth = props.strokeWidth; const previewResource = () => { window.open(resourceUrl); }; if (resourceType === "image/*") { return ( showPreviewImageDialog(resourceUrl)} decoding="async" loading="lazy" /> ); } const getResourceIcon = () => { switch (resourceType) { case "video/*": return ; case "audio/*": return ; case "text/*": return ; case "application/epub+zip": return ; case "application/pdf": return ; case "application/msword": return ; case "application/msexcel": return ; case "application/zip": return ; case "application/x-java-archive": return ; default: return ; } }; return (
{getResourceIcon()}
); }; export default React.memo(ResourceIcon);