spee.ch/react/components/AssetPreview/index.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

import React from 'react';
import { Link } from 'react-router-dom';
2018-01-31 19:40:26 +01:00
const AssetPreview = ({ name, claimId, fileExt, contentType }) => {
const directSourceLink = `${claimId}/${name}.${fileExt}`;
2018-02-23 20:04:17 +01:00
const showUrlLink = `/${claimId}/${name}`;
return (
<div className='asset-holder'>
<Link to={showUrlLink} >
{(() => {
switch (contentType) {
case 'image/jpeg':
case 'image/jpg':
case 'image/png':
return (
<img className={'asset-preview'} src={directSourceLink} alt={name} />
);
case 'image/gif':
return (
<img className={'asset-preview'} src={directSourceLink} alt={name} />
);
case 'video/mp4':
return (
2018-02-07 07:28:17 +01:00
<video className={'asset-preview'}>
<source src={directSourceLink} type={contentType} />
</video>
);
default:
return (
<p>unsupported file type</p>
);
}
})()}
</Link>
</div>
);
};
export default AssetPreview;