onedrive/components/previews/ImagePreview.tsx

34 lines
964 B
TypeScript
Raw Normal View History

import type { OdFileObject } from '../../types'
import { FC } from 'react'
2022-02-14 11:33:19 +00:00
import { useRouter } from 'next/router'
import { PreviewContainer, DownloadBtnContainer } from './Containers'
import DownloadButtonGroup from '../DownloadBtnGtoup'
2022-02-14 11:33:19 +00:00
import { getStoredToken } from '../../utils/protectedRouteHandler'
const ImagePreview: FC<{ file: OdFileObject }> = ({ file }) => {
2022-02-14 11:33:19 +00:00
const { asPath } = useRouter()
const hashedToken = getStoredToken(asPath)
return (
<>
<PreviewContainer>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
className="mx-auto"
2022-02-14 11:33:19 +00:00
src={`/api/raw/?path=${asPath}${hashedToken ? `&odpt=${hashedToken}` : ''}`}
alt={file.name}
width={file.image?.width}
height={file.image?.height}
/>
</PreviewContainer>
<DownloadBtnContainer>
2022-02-14 11:33:19 +00:00
<DownloadButtonGroup />
</DownloadBtnContainer>
</>
)
}
export default ImagePreview