summaryrefslogtreecommitdiffstats
path: root/webapp/components/file_info_preview.jsx
blob: 2491c986d2b8d6235bf7f54529e0885ae0bc3ca7 (plain)
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
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import React from 'react';

import * as Utils from 'utils/utils.jsx';

export default class FileInfoPreview extends React.Component {
    shouldComponentUpdate(nextProps) {
        if (nextProps.fileUrl !== this.props.fileUrl) {
            return true;
        }

        if (!Utils.areObjectsEqual(nextProps.fileInfo, this.props.fileInfo)) {
            return true;
        }

        return false;
    }

    render() {
        const fileInfo = this.props.fileInfo;
        const fileUrl = this.props.fileUrl;

        // non-image files include a section providing details about the file
        const infoParts = [];

        if (fileInfo.extension !== '') {
            infoParts.push(Utils.localizeMessage('file_info_preview.type', 'File type ') + fileInfo.extension.toUpperCase());
        }

        infoParts.push(Utils.localizeMessage('file_info_preview.size', 'Size ') + Utils.fileSizeToString(fileInfo.size));

        const infoString = infoParts.join(', ');

        return (
            <div className='file-details__container'>
                <a
                    className={'file-details__preview'}
                    to={fileUrl}
                    target='_blank'
                    rel='noopener noreferrer'
                >
                    <span className='file-details__preview-helper'/>
                    <img src={Utils.getFileIconPath(fileInfo)}/>
                </a>
                <div className='file-details'>
                    <div className='file-details__name'>{fileInfo.name}</div>
                    <div className='file-details__info'>{infoString}</div>
                </div>
            </div>
        );
    }
}

FileInfoPreview.propTypes = {
    fileInfo: React.PropTypes.object.isRequired,
    fileUrl: React.PropTypes.string.isRequired
};