This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
file_thumbnail.jsx
67 lines (55 loc) · 1.89 KB
/
file_thumbnail.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import PropTypes from 'prop-types';
import React from 'react';
import {getFileThumbnailUrl, getFileUrl} from 'mattermost-redux/utils/file_utils';
import Constants, {FileTypes} from 'utils/constants.jsx';
import {
getFileType,
getIconClassName,
isGIFImage
} from 'utils/utils.jsx';
export default class FileThumbnail extends React.PureComponent {
static propTypes = {
/*
* File detailed information
*/
fileInfo: PropTypes.object.isRequired
}
render() {
const {fileInfo} = this.props;
const type = getFileType(fileInfo.extension);
let thumbnail;
if (type === FileTypes.IMAGE) {
let className = 'post-image';
if (fileInfo.width < Constants.THUMBNAIL_WIDTH && fileInfo.height < Constants.THUMBNAIL_HEIGHT) {
className += ' small';
} else {
className += ' normal';
}
let thumbnailUrl = getFileThumbnailUrl(fileInfo.id);
if (isGIFImage(fileInfo.extension) && !fileInfo.has_preview_image) {
thumbnailUrl = getFileUrl(fileInfo.id);
}
return (
<div
className={className}
style={{
backgroundImage: `url(${thumbnailUrl})`,
backgroundSize: 'cover'
}}
/>
);
} else if (fileInfo.extension === FileTypes.SVG) {
thumbnail = (
<img
className='post-image normal'
src={getFileUrl(fileInfo.id)}
/>
);
} else {
thumbnail = <div className={'file-icon ' + getIconClassName(type)}/>;
}
return thumbnail;
}
}