import { useTranslation } from 'next-i18next' import FourOhFour from '../FourOhFour' import Loading from '../Loading' import { DownloadButton } from '../DownloadBtnGtoup' import useAxiosGet from '../../utils/fetchOnMount' import { DownloadBtnContainer, PreviewContainer } from './Containers' const parseDotUrl = (content: string): string | undefined => { return content .split('\n') .find(line => line.startsWith('URL=')) ?.split('=')[1] } const TextPreview = ({ file }) => { const { t } = useTranslation() const { response: content, error, validating } = useAxiosGet(file['@microsoft.graph.downloadUrl']) if (error) { return ( ) } if (validating) { return ( ) } if (!content) { return ( ) } return (
{content}
window.open(parseDotUrl(content) || '')} btnColor="blue" btnText={t('Open URL')} btnIcon="external-link-alt" btnTitle={t('Open URL{{url}}', { url: ' ' + parseDotUrl(content) || '' })} />
) } export default TextPreview