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