Fix uploaded files being previewed on wrong channels (#2860)

Этот коммит содержится в:
Joram Wilander
2016-05-03 11:00:06 -04:00
родитель 3a17fd86a0
Коммит 05a203b409
2 изменённых файлов: 13 добавлений и 9 удалений

Просмотреть файл

@@ -253,9 +253,11 @@ class CreatePost extends React.Component {
draft.previews = draft.previews.concat(filenames); draft.previews = draft.previews.concat(filenames);
PostStore.storeDraft(channelId, draft); 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; let message = err;
if (message && typeof message !== 'string') { if (message && typeof message !== 'string') {
// err is an AppError from the server // err is an AppError from the server
@@ -263,16 +265,18 @@ class CreatePost extends React.Component {
} }
if (clientId !== -1) { if (clientId !== -1) {
const draft = PostStore.getDraft(this.state.channelId); const draft = PostStore.getDraft(channelId);
const index = draft.uploadsInProgress.indexOf(clientId); const index = draft.uploadsInProgress.indexOf(clientId);
if (index !== -1) { if (index !== -1) {
draft.uploadsInProgress.splice(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}); this.setState({serverError: message});

Просмотреть файл

@@ -49,15 +49,15 @@ class FileUpload extends React.Component {
fileUploadSuccess(channelId, data) { fileUploadSuccess(channelId, data) {
this.props.onFileUpload(data.filenames, data.client_ids, channelId); 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++) { for (var j = 0; j < data.client_ids.length; j++) {
Reflect.deleteProperty(requests, data.client_ids[j]); Reflect.deleteProperty(requests, data.client_ids[j]);
} }
this.setState({requests}); this.setState({requests});
} }
fileUploadFail(clientId, err) { fileUploadFail(clientId, channelId, err) {
this.props.onUploadError(err, clientId); this.props.onUploadError(err, clientId, channelId);
} }
uploadFiles(files) { uploadFiles(files) {
@@ -86,7 +86,7 @@ class FileUpload extends React.Component {
channelId, channelId,
clientId, clientId,
this.fileUploadSuccess.bind(this, channelId), this.fileUploadSuccess.bind(this, channelId),
this.fileUploadFail.bind(this, clientId) this.fileUploadFail.bind(this, clientId, channelId)
); );
const requests = this.state.requests; const requests = this.state.requests;