overleaf/services/web/frontend/js/features/binary-file/components/binary-file-image.js
Jakob Ackermann 8f0a0439cd Merge pull request #4069 from overleaf/as-file-views-use-context
Pull project id from `EditorContext` instead of `window` in file views

GitOrigin-RevId: 78c2686d8bcd1e95414631ca77143fd9ae3edbc6
2021-05-22 02:05:56 +00:00

26 lines
673 B
JavaScript

import React from 'react'
import PropTypes from 'prop-types'
import { useEditorContext } from '../../../shared/context/editor-context'
export default function BinaryFileImage({ fileName, fileId, onLoad, onError }) {
const { projectId } = useEditorContext({
projectId: PropTypes.string.isRequired,
})
return (
<img
src={`/project/${projectId}/file/${fileId}`}
onLoad={onLoad}
onError={onError}
onAbort={onError}
alt={fileName}
/>
)
}
BinaryFileImage.propTypes = {
fileName: PropTypes.string.isRequired,
fileId: PropTypes.string.isRequired,
onLoad: PropTypes.func.isRequired,
onError: PropTypes.func.isRequired,
}