export default function FilePreview(props: any) {
const { fileUrl } = props;
const [fileType, setFileType] = useState('');
useEffect(() => {
const type = fileUrl.split('.')[fileUrl.split('.').length - 1];
setFileType(type);
}, [fileUrl]);
if (fileType === 'pdf') {
return <embed src={fileUrl} type="application/pdf" width="100%" height="99.7%" />;
}
if (['xlsx', 'docx'].includes(fileType)) {
return (
<iframe
src={`https://view.officeapps.live.com/op/embed.aspx?src=${fileUrl}`}
width="100%"
height="92%"
frameBorder="0"
/>
);
}
if (fileType === 'txt') {
return <iframe id="txtFrame" src={fileUrl} width="100%" height="92%" frameBorder="0"></iframe>;
}
return null;
}