From 05a203b409ae461a99ca6f6e21d867c81ba071fa Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Tue, 3 May 2016 11:00:06 -0400 Subject: Fix uploaded files being previewed on wrong channels (#2860) --- webapp/components/create_post.jsx | 14 +++++++++----- webapp/components/file_upload.jsx | 8 ++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/webapp/components/create_post.jsx b/webapp/components/create_post.jsx index 9bbc44f38..011e0c2b8 100644 --- a/webapp/components/create_post.jsx +++ b/webapp/components/create_post.jsx @@ -253,9 +253,11 @@ class CreatePost extends React.Component { draft.previews = draft.previews.concat(filenames); PostStore.storeDraft(channelId, draft); - this.setState({uploadsInProgress: draft.uploadsInProgress, previews: draft.previews}); + if (channelId === this.state.channelId) { + this.setState({uploadsInProgress: draft.uploadsInProgress, previews: draft.previews}); + } } - handleUploadError(err, clientId) { + handleUploadError(err, clientId, channelId) { let message = err; if (message && typeof message !== 'string') { // err is an AppError from the server @@ -263,16 +265,18 @@ class CreatePost extends React.Component { } if (clientId !== -1) { - const draft = PostStore.getDraft(this.state.channelId); + const draft = PostStore.getDraft(channelId); const index = draft.uploadsInProgress.indexOf(clientId); if (index !== -1) { draft.uploadsInProgress.splice(index, 1); } - PostStore.storeDraft(this.state.channelId, draft); + PostStore.storeDraft(channelId, draft); - this.setState({uploadsInProgress: draft.uploadsInProgress}); + if (channelId === this.state.channelId) { + this.setState({uploadsInProgress: draft.uploadsInProgress}); + } } this.setState({serverError: message}); diff --git a/webapp/components/file_upload.jsx b/webapp/components/file_upload.jsx index 8e4019f6f..8e631ac95 100644 --- a/webapp/components/file_upload.jsx +++ b/webapp/components/file_upload.jsx @@ -49,15 +49,15 @@ class FileUpload extends React.Component { fileUploadSuccess(channelId, data) { this.props.onFileUpload(data.filenames, data.client_ids, channelId); - const requests = JSON.parse(JSON.stringify(this.state.requests)); + const requests = Object.assign({}, this.state.requests); for (var j = 0; j < data.client_ids.length; j++) { Reflect.deleteProperty(requests, data.client_ids[j]); } this.setState({requests}); } - fileUploadFail(clientId, err) { - this.props.onUploadError(err, clientId); + fileUploadFail(clientId, channelId, err) { + this.props.onUploadError(err, clientId, channelId); } uploadFiles(files) { @@ -86,7 +86,7 @@ class FileUpload extends React.Component { channelId, clientId, this.fileUploadSuccess.bind(this, channelId), - this.fileUploadFail.bind(this, clientId) + this.fileUploadFail.bind(this, clientId, channelId) ); const requests = this.state.requests; -- cgit v1.2.3-1-g7c22