mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-23 11:36:38 +08:00
### What problem does this PR solve? Refactor: UmiJs -> Vite+React ### Type of change - [x] Refactoring --------- Co-authored-by: Liu An <asiro@qq.com>
34 lines
830 B
TypeScript
34 lines
830 B
TypeScript
import { getExtension } from '@/utils/document-util';
|
|
import SvgIcon from '../svg-icon';
|
|
|
|
import { useFetchDocumentThumbnailsByIds } from '@/hooks/use-document-request';
|
|
import { useEffect } from 'react';
|
|
import styles from './index.module.less';
|
|
|
|
interface IProps {
|
|
name: string;
|
|
id: string;
|
|
}
|
|
|
|
const FileIcon = ({ name, id }: IProps) => {
|
|
const fileExtension = getExtension(name);
|
|
|
|
const { data: fileThumbnails, setDocumentIds } =
|
|
useFetchDocumentThumbnailsByIds();
|
|
const fileThumbnail = fileThumbnails[id];
|
|
|
|
useEffect(() => {
|
|
if (id) {
|
|
setDocumentIds([id]);
|
|
}
|
|
}, [id, setDocumentIds]);
|
|
|
|
return fileThumbnail ? (
|
|
<img src={fileThumbnail} className={styles.thumbnailImg}></img>
|
|
) : (
|
|
<SvgIcon name={`file-icon/${fileExtension}`} width={24}></SvgIcon>
|
|
);
|
|
};
|
|
|
|
export default FileIcon;
|