summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-01-04 15:57:22 -0500
committerChristopher Speller <crspeller@gmail.com>2016-01-04 15:57:22 -0500
commit0c6483b60a230251c6704b85de0c203da37737dc (patch)
tree83bc733c1ec790203429dfb4d056ec44fead6e30 /web
parent67db3ca8ce5e78ee55c37a3dbfb8e5d44037a324 (diff)
parent4b76d6a05d0142c9d1addca698a922e8929674e1 (diff)
downloadchat-0c6483b60a230251c6704b85de0c203da37737dc.tar.gz
chat-0c6483b60a230251c6704b85de0c203da37737dc.tar.bz2
chat-0c6483b60a230251c6704b85de0c203da37737dc.zip
Merge pull request #1801 from hmhealey/plt1602
PLT-1602 Fix ViewImageModal incorrectly assuming it has a file's info in certain cases
Diffstat (limited to 'web')
-rw-r--r--web/react/components/view_image.jsx42
-rw-r--r--web/react/utils/utils.jsx10
2 files changed, 35 insertions, 17 deletions
diff --git a/web/react/components/view_image.jsx b/web/react/components/view_image.jsx
index 7edf6283b..196a44bd0 100644
--- a/web/react/components/view_image.jsx
+++ b/web/react/components/view_image.jsx
@@ -31,19 +31,12 @@ export default class ViewImageModal extends React.Component {
this.onMouseEnterImage = this.onMouseEnterImage.bind(this);
this.onMouseLeaveImage = this.onMouseLeaveImage.bind(this);
- const loaded = [];
- const progress = [];
- for (var i = 0; i < this.props.filenames.length; i++) {
- loaded.push(false);
- progress.push(0);
- }
-
this.state = {
imgId: this.props.startId,
- fileInfo: new Map(),
+ fileInfo: null,
imgHeight: '100%',
- loaded,
- progress,
+ loaded: Utils.fillArray(false, this.props.filenames.length),
+ progress: Utils.fillArray(0, this.props.filenames.length),
showFooter: false
};
}
@@ -104,17 +97,28 @@ export default class ViewImageModal extends React.Component {
} else if (nextProps.show === false && this.props.show === true) {
this.onModalHidden();
}
+
+ if (!Utils.areObjectsEqual(this.props.filenames, nextProps.filenames)) {
+ this.setState({
+ loaded: Utils.fillArray(false, nextProps.filenames.length),
+ progress: Utils.fillArray(0, nextProps.filenames.length)
+ });
+ }
}
onFileStoreChange(filename) {
const id = this.props.filenames.indexOf(filename);
- if (id !== -1 && !this.state.loaded[id]) {
- const fileInfo = this.state.fileInfo;
- fileInfo.set(filename, FileStore.getInfo(filename));
- this.setState({fileInfo});
+ if (id !== -1) {
+ if (id === this.state.imgId) {
+ this.setState({
+ fileInfo: FileStore.getInfo(filename)
+ });
+ }
- this.loadImage(id, filename);
+ if (!this.state.loaded[id]) {
+ this.loadImage(id, filename);
+ }
}
}
@@ -132,6 +136,10 @@ export default class ViewImageModal extends React.Component {
return;
}
+ this.setState({
+ fileInfo: FileStore.getInfo(filename)
+ });
+
if (!this.state.loaded[id]) {
this.loadImage(id, filename);
}
@@ -227,8 +235,8 @@ export default class ViewImageModal extends React.Component {
var content;
if (this.state.loaded[this.state.imgId]) {
- // if a file has been loaded, we also have its info
- const fileInfo = this.state.fileInfo.get(filename);
+ // this.state.fileInfo is for the current image and we shoudl have it before we load the image
+ const fileInfo = this.state.fileInfo;
const extension = Utils.splitFileLocation(filename).ext;
const fileType = Utils.getFileType(extension);
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index 24d27b10a..a808c9be3 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -1261,3 +1261,13 @@ export function isFeatureEnabled(feature) {
export function isSystemMessage(post) {
return post.type && (post.type.lastIndexOf(Constants.SYSTEM_MESSAGE_PREFIX) === 0);
}
+
+export function fillArray(value, length) {
+ const arr = [];
+
+ for (let i = 0; i < length; i++) {
+ arr.push(value);
+ }
+
+ return arr;
+}