import { FC, useEffect, useState } from 'react'; import clsx from 'clsx'; import { path, shell } from '@tauri-apps/api'; import { chatRoot } from '@/utils'; interface FilePathProps { paths?: string; label?: string; className?: string; content?: string; url?: string; } const FilePath: FC = ({ className, label = 'PATH', paths = '', url, content }) => { const [filePath, setPath] = useState(''); useEffect(() => { if (!path && !url) return; (async () => { if (url) { setPath(url); return; } setPath(await path.join(await chatRoot(), ...paths.split('/').filter((i) => !!i))); })(); }, [url, paths]); return (
{label}:{' '} shell.open(filePath)} title={filePath}> {content ? content : filePath}
); }; export default FilePath;