2024-01-26 04:23:48 -05:00
|
|
|
import { useProjectContext } from '../../../shared/context/project-context'
|
2024-08-21 07:28:21 -04:00
|
|
|
import { useSnapshotContext } from '@/features/ide-react/context/snapshot-context'
|
|
|
|
import { BinaryFile } from '@/features/file-view/types/binary-file'
|
2024-01-26 04:23:48 -05:00
|
|
|
|
|
|
|
export default function FileViewImage({
|
2024-08-21 07:28:21 -04:00
|
|
|
file,
|
2024-01-26 04:23:48 -05:00
|
|
|
onLoad,
|
|
|
|
onError,
|
|
|
|
}: {
|
2024-08-21 07:28:21 -04:00
|
|
|
file: BinaryFile
|
2024-01-26 04:23:48 -05:00
|
|
|
onLoad: () => void
|
|
|
|
onError: () => void
|
|
|
|
}) {
|
|
|
|
const { _id: projectId } = useProjectContext()
|
2024-08-21 07:28:21 -04:00
|
|
|
const { fileTreeFromHistory } = useSnapshotContext()
|
2024-01-26 04:23:48 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<img
|
2024-08-21 07:28:21 -04:00
|
|
|
src={
|
|
|
|
fileTreeFromHistory
|
|
|
|
? `/project/${projectId}/blob/${file.hash}`
|
|
|
|
: `/project/${projectId}/file/${file.id}`
|
|
|
|
}
|
2024-01-26 04:23:48 -05:00
|
|
|
onLoad={onLoad}
|
|
|
|
onError={onError}
|
2024-08-21 07:28:21 -04:00
|
|
|
alt={file.name}
|
2024-01-26 04:23:48 -05:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|