2019-03-28 10:59:43 +08:00
|
|
|
import React from 'react';
|
2019-03-29 15:30:44 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2019-03-28 10:59:43 +08:00
|
|
|
import { gettext } from '../../utils/constants';
|
|
|
|
|
2020-03-16 11:42:26 +08:00
|
|
|
const { err, trafficOverLimit, zipped, filePath, canDownload } = window.shared.pageOptions;
|
2019-03-29 15:30:44 +08:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
errorMsg: PropTypes.string
|
|
|
|
};
|
2019-03-28 10:59:43 +08:00
|
|
|
|
|
|
|
class SharedFileViewTip extends React.Component {
|
|
|
|
render() {
|
|
|
|
let errorMsg;
|
|
|
|
if (err == 'File preview unsupported') {
|
|
|
|
errorMsg = <p>{gettext('Online view is not applicable to this file format')}</p>;
|
|
|
|
} else {
|
2019-03-29 15:30:44 +08:00
|
|
|
errorMsg = <p className="error">{err || this.props.errorMsg}</p>;
|
2019-03-28 10:59:43 +08:00
|
|
|
}
|
2020-03-16 11:42:26 +08:00
|
|
|
|
|
|
|
let isShowDownloadBtn = canDownload && !trafficOverLimit;
|
|
|
|
|
2019-03-28 10:59:43 +08:00
|
|
|
return (
|
|
|
|
<div className="shared-file-view-body">
|
2020-03-16 11:42:26 +08:00
|
|
|
<div className={`file-view-tip ${!isShowDownloadBtn ? 'pt-7' : ''}`}>
|
2019-03-28 10:59:43 +08:00
|
|
|
{errorMsg}
|
2020-03-16 11:42:26 +08:00
|
|
|
{isShowDownloadBtn &&
|
2019-08-28 11:23:15 +08:00
|
|
|
<a href={`?${zipped ? 'p=' + encodeURIComponent(filePath) + '&' : ''}dl=1`} className="btn btn-secondary">{gettext('Download')}</a>
|
2019-03-29 15:30:44 +08:00
|
|
|
}
|
2019-03-28 10:59:43 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-29 15:30:44 +08:00
|
|
|
SharedFileViewTip.propTypes = propTypes;
|
|
|
|
|
2019-03-28 10:59:43 +08:00
|
|
|
export default SharedFileViewTip;
|