import React, { useMemo } from "react"; import { Image, Button, Row, Col, Tooltip } from "antd"; import { PostDto } from "@nice/common"; import { env } from "@web/src/env"; import { getFileIcon } from "./utils"; import { formatFileSize, getCompressedImageUrl } from "@nice/utils"; import { useNavigate } from "react-router-dom"; export default function PostResources({ post }: { post: PostDto }) { const { resources } = useMemo(() => { if (!post?.resources) return { resources: [] }; const isImage = (url: string) => /\.(png|jpg|jpeg|gif|webp)$/i.test(url); const sortedResources = post.resources .map((resource) => { const original = `http://${env.SERVER_IP}:${env.UPLOAD_PORT}/uploads/${resource.url}`; const isImg = isImage(resource.url); return { ...resource, url: isImg ? getCompressedImageUrl(original) : original, originalUrl: original, isImage: isImg, }; }) .sort((a, b) => (a.isImage === b.isImage ? 0 : a.isImage ? -1 : 1)); return { resources: sortedResources }; }, [post]); const imageResources = resources.filter((res) => res.isImage); const fileResources = resources.filter((res) => !res.isImage); return (