onedrive/components/previews/TextPreview.tsx

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-06-25 14:15:00 +00:00
import FourOhFour from '../FourOhFour'
import Loading from '../Loading'
import DownloadButtonGroup from '../DownloadBtnGtoup'
import useAxiosGet from '../../utils/fetchOnMount'
import { DownloadBtnContainer, PreviewContainer } from './Containers'
2021-06-25 14:15:00 +00:00
const TextPreview = ({ file }) => {
const { content, error, validating } = useAxiosGet(file['@microsoft.graph.downloadUrl'])
2021-06-25 14:15:00 +00:00
if (error) {
return (
<PreviewContainer>
<FourOhFour errorMsg={error} />
</PreviewContainer>
2021-06-25 14:15:00 +00:00
)
}
if (validating) {
2021-06-25 14:15:00 +00:00
return (
<PreviewContainer>
2021-06-25 14:15:00 +00:00
<Loading loadingText="Loading file content..." />
</PreviewContainer>
)
}
if (!content) {
return (
<PreviewContainer>
<FourOhFour errorMsg="File is empty." />
</PreviewContainer>
2021-06-25 14:15:00 +00:00
)
}
return (
<div>
<PreviewContainer>
<pre className="md:p-3 p-0 overflow-x-scroll text-sm">{content}</pre>
</PreviewContainer>
<DownloadBtnContainer>
<DownloadButtonGroup downloadUrl={file['@microsoft.graph.downloadUrl']} />
</DownloadBtnContainer>
</div>
2021-06-25 14:15:00 +00:00
)
}
export default TextPreview