import { useEffect, useState } from 'react' import prettyBytes from 'pretty-bytes' import { useAuthentication } from 'utils/authentication' import { MessageContentProps } from '.' import { Loader } from 'components/design/Loader' import { IconButton } from 'components/design/IconButton' export interface FileData { blob: Blob url: string } export const MessageFile: React.FC = (props) => { const { authentication } = useAuthentication() const [file, setFile] = useState(null) useEffect(() => { const fetchData = async (): Promise => { const { data } = await authentication.api.get(props.value, { responseType: 'blob' }) const fileURL = URL.createObjectURL(data) setFile({ blob: data, url: fileURL }) } fetchData().catch(() => {}) }, []) if (file == null) { return } if (props.mimetype.startsWith('image/')) { return ( <> ) } if (props.mimetype.startsWith('audio/')) { return ( ) } if (props.mimetype.startsWith('video/')) { return ( <> ) } return ( <>
file
{file.blob.type}
{prettyBytes(file.blob.size)}
) }