onedrive/components/previews/TextPreview.tsx
myl7 49a601446d
add translations for preview components
also fix ellipsis in zh-CN
2022-02-06 20:34:03 +08:00

49 lines
1.2 KiB
TypeScript

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