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

44 lines
1.2 KiB
JavaScript
Raw Normal View History

import React from 'react';
import { Link } from 'react-router-dom';
2018-03-02 18:36:28 +01:00
const { claim: { defaultThumbnail } } = require('../../../config/speechConfig.js');
2018-03-02 18:36:28 +01:00
const AssetPreview = ({ claimData: { name, claimId, fileExt, contentType, thumbnail } }) => {
2018-01-31 19:40:26 +01:00
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':
case 'image/gif':
return (
2018-03-02 18:36:28 +01:00
<img
className={'asset-preview'}
src={directSourceLink}
alt={name}
/>
);
case 'video/mp4':
return (
2018-03-02 18:36:28 +01:00
<img
2018-03-04 21:17:03 +01:00
className={'asset-preview video'}
2018-03-02 18:36:28 +01:00
src={thumbnail || defaultThumbnail}
alt={name}
/>
);
default:
return (
<p>unsupported file type</p>
);
}
})()}
</Link>
</div>
);
};
export default AssetPreview;