file-view-image.tsx 729 B

1234567891011121314151617181920212223242526272829
  1. import { useProjectContext } from '../../../shared/context/project-context'
  2. import { useSnapshotContext } from '@/features/ide-react/context/snapshot-context'
  3. import { BinaryFile } from '@/features/file-view/types/binary-file'
  4. export default function FileViewImage({
  5. file,
  6. onLoad,
  7. onError,
  8. }: {
  9. file: BinaryFile
  10. onLoad: () => void
  11. onError: () => void
  12. }) {
  13. const { _id: projectId } = useProjectContext()
  14. const { fileTreeFromHistory } = useSnapshotContext()
  15. return (
  16. <img
  17. src={
  18. fileTreeFromHistory
  19. ? `/project/${projectId}/blob/${file.hash}`
  20. : `/project/${projectId}/file/${file.id}`
  21. }
  22. onLoad={onLoad}
  23. onError={onError}
  24. alt={file.name}
  25. />
  26. )
  27. }