summaryrefslogtreecommitdiffstats
path: root/web/react/components/file_attachment.jsx
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-07-28 11:53:05 -0400
committerhmhealey <harrisonmhealey@gmail.com>2015-07-29 10:03:42 -0400
commit411f8cb9effef0310abbb39f9ae53adf6ecf8aaf (patch)
treed29255621e625fe950fa0d22f97a069d1ebc93fa /web/react/components/file_attachment.jsx
parentf66cd5e9773a38cca635d33d91f0ef3b056d94a0 (diff)
downloadchat-411f8cb9effef0310abbb39f9ae53adf6ecf8aaf.tar.gz
chat-411f8cb9effef0310abbb39f9ae53adf6ecf8aaf.tar.bz2
chat-411f8cb9effef0310abbb39f9ae53adf6ecf8aaf.zip
Fixed FileAttachment component to not spam the server with requests when displaying a zero byte file
Diffstat (limited to 'web/react/components/file_attachment.jsx')
-rw-r--r--web/react/components/file_attachment.jsx11
1 files changed, 8 insertions, 3 deletions
diff --git a/web/react/components/file_attachment.jsx b/web/react/components/file_attachment.jsx
index e730af5f2..346819bdd 100644
--- a/web/react/components/file_attachment.jsx
+++ b/web/react/components/file_attachment.jsx
@@ -12,7 +12,7 @@ module.exports = React.createClass({
handleImageClick: React.PropTypes.func
},
getInitialState: function() {
- return {fileSize: 0};
+ return {fileSize: -1};
},
componentDidMount: function() {
var filename = this.props.filenames[this.props.index];
@@ -80,7 +80,7 @@ module.exports = React.createClass({
thumbnail = <div className={"file-icon "+utils.getIconClassName(type)}/>;
}
- if (!this.state.fileSize) {
+ if (this.state.fileSize < 0) {
var self = this;
// asynchronously request the size of the file so that we can display it next to the thumbnail
@@ -89,6 +89,11 @@ module.exports = React.createClass({
});
}
+ var fileSizeString = "";
+ if (this.state.fileSize >= 0) {
+ fileSizeString = utils.fileSizeToString(this.state.fileSize);
+ }
+
return (
<div className="post-image__column" key={filename}>
<a className="post-image__thumbnail" href="#" onClick={this.props.handleImageClick}
@@ -99,7 +104,7 @@ module.exports = React.createClass({
<div className="post-image__name">{fileInfo.name}</div>
<div>
<span className="post-image__type">{fileInfo.ext.toUpperCase()}</span>
- <span className="post-image__size">{this.state.fileSize ? utils.fileSizeToString(this.state.fileSize) : ""}</span>
+ <span className="post-image__size">{this.fileSizeString}</span>
</div>
</div>
</div>