feat: Add FileIcon #1880 (#1960)

### What problem does this PR solve?

feat: Add FileIcon #1880

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-08-15 14:39:56 +08:00
committed by GitHub
parent bd19656c8f
commit 5169299826
5 changed files with 172 additions and 42 deletions

View File

@ -0,0 +1,3 @@
.thumbnailImg {
max-width: 20px;
}

View File

@ -0,0 +1,25 @@
import { getExtension } from '@/utils/document-util';
import SvgIcon from '../svg-icon';
import { useSelectFileThumbnails } from '@/hooks/knowledge-hooks';
import styles from './index.less';
interface IProps {
name: string;
id: string;
}
const FileIcon = ({ name, id }: IProps) => {
const fileExtension = getExtension(name);
// TODO: replace this line with react query
const fileThumbnails = useSelectFileThumbnails();
const fileThumbnail = fileThumbnails[id];
return fileThumbnail ? (
<img src={fileThumbnail} className={styles.thumbnailImg}></img>
) : (
<SvgIcon name={`file-icon/${fileExtension}`} width={24}></SvgIcon>
);
};
export default FileIcon;