2018-01-30 20:46:22 +01:00
|
|
|
import React from 'react';
|
2018-01-31 23:50:35 +01:00
|
|
|
import { Link } from 'react-router-dom';
|
2018-01-30 20:46:22 +01:00
|
|
|
|
2018-01-31 19:40:26 +01:00
|
|
|
const AssetPreview = ({ name, claimId, fileExt, contentType }) => {
|
|
|
|
const directSourceLink = `${claimId}/${name}.${fileExt}`;
|
2018-01-31 23:50:35 +01:00
|
|
|
const showUrlLink = `${claimId}/${name}`;
|
2018-01-31 19:40:26 +01:00
|
|
|
const previewHolderStyle = {
|
|
|
|
clear: 'both',
|
|
|
|
display: 'inline-block',
|
|
|
|
width: '31%',
|
|
|
|
padding: '0px',
|
|
|
|
margin: '1%',
|
|
|
|
backgroundColor: 'black',
|
|
|
|
};
|
|
|
|
const assetStyle = {
|
|
|
|
width: '100%',
|
|
|
|
padding: '0px',
|
|
|
|
margin: '0px',
|
|
|
|
};
|
|
|
|
switch (contentType) {
|
|
|
|
case 'image/jpeg':
|
|
|
|
case 'image/jpg':
|
|
|
|
case 'image/png':
|
|
|
|
return (
|
|
|
|
<div style={previewHolderStyle}>
|
2018-01-31 23:50:35 +01:00
|
|
|
<Link to={showUrlLink} >
|
|
|
|
<img style={assetStyle} className={'asset-preview--image'} src={directSourceLink} alt={name} />
|
|
|
|
</Link>
|
2018-01-31 19:40:26 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
case 'image/gif':
|
|
|
|
return (
|
|
|
|
<div style={previewHolderStyle}>
|
|
|
|
<img style={assetStyle} className={'asset-preview--gif'} src={directSourceLink} alt={name} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
case 'video/mp4':
|
|
|
|
return (
|
|
|
|
<div style={previewHolderStyle}>
|
|
|
|
<video style={assetStyle}>
|
|
|
|
<source src={directSourceLink} type={contentType} />
|
|
|
|
</video>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return (
|
|
|
|
<p>unsupported file type</p>
|
|
|
|
);
|
|
|
|
}
|
2018-01-30 20:46:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default AssetPreview;
|