2020-03-02 00:21:43 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
2020-03-18 23:31:02 +01:00
|
|
|
import { getExtension, getType } from '../../utils';
|
2020-03-16 13:37:10 +01:00
|
|
|
|
|
|
|
import BrokenFile from '../../icons/BrokenFile';
|
2020-03-02 00:21:43 +01:00
|
|
|
import FileIcon from '../FileIcon';
|
2020-03-24 22:57:41 +01:00
|
|
|
import VideoPreview from '../VideoPreview';
|
2020-03-02 00:21:43 +01:00
|
|
|
import Wrapper from './Wrapper';
|
|
|
|
import Image from './Image';
|
|
|
|
|
2020-03-24 15:45:01 +01:00
|
|
|
const CardPreview = ({ hasError, url, type, withFileCaching }) => {
|
2020-03-16 13:37:10 +01:00
|
|
|
const isFile = getType(type) === 'file';
|
2020-03-24 22:57:41 +01:00
|
|
|
const isVideo = getType(type) === 'video';
|
2020-03-10 11:32:52 +01:00
|
|
|
|
2020-03-16 15:33:58 +01:00
|
|
|
if (hasError) {
|
|
|
|
return (
|
|
|
|
<Wrapper isFile>
|
|
|
|
<BrokenFile />
|
|
|
|
</Wrapper>
|
|
|
|
);
|
|
|
|
}
|
2020-03-10 11:32:52 +01:00
|
|
|
|
2020-03-24 22:57:41 +01:00
|
|
|
if (isFile) {
|
|
|
|
return (
|
|
|
|
<Wrapper isFile>
|
|
|
|
<FileIcon ext={getExtension(type)} />
|
|
|
|
</Wrapper>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-20 23:19:18 +01:00
|
|
|
return (
|
2020-03-24 22:57:41 +01:00
|
|
|
<Wrapper>
|
|
|
|
{isVideo ? (
|
2020-03-25 21:43:28 +01:00
|
|
|
<VideoPreview src={url} />
|
2020-03-24 22:57:41 +01:00
|
|
|
) : (
|
2020-03-24 15:45:01 +01:00
|
|
|
<Image src={`${url}${withFileCaching ? `?${performance.now()}` : ''}`} />
|
2020-03-24 22:57:41 +01:00
|
|
|
)}
|
2020-03-20 23:19:18 +01:00
|
|
|
</Wrapper>
|
|
|
|
);
|
2020-03-02 00:21:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
CardPreview.defaultProps = {
|
2020-03-10 11:32:52 +01:00
|
|
|
hasError: false,
|
2020-03-02 00:21:43 +01:00
|
|
|
url: null,
|
2020-03-06 17:19:20 +01:00
|
|
|
type: '',
|
2020-03-24 15:45:01 +01:00
|
|
|
withFileCaching: true,
|
2020-03-02 00:21:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
CardPreview.propTypes = {
|
2020-03-10 11:32:52 +01:00
|
|
|
hasError: PropTypes.bool,
|
2020-03-02 00:21:43 +01:00
|
|
|
url: PropTypes.string,
|
|
|
|
type: PropTypes.string,
|
2020-03-24 15:45:01 +01:00
|
|
|
withFileCaching: PropTypes.bool,
|
2020-03-02 00:21:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default CardPreview;
|