Changed post drafts to maintain a store a unique id for each file upload to fix issues with duplicate file names

Этот коммит содержится в:
hmhealey
2015-08-10 12:05:45 -04:00
родитель 4b74c873cc
Коммит c9a1bf2d33
7 изменённых файлов: 79 добавлений и 58 удалений

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

@@ -128,7 +128,7 @@ module.exports = React.createClass({
$(".post-list-holder-by-time").css("height", height + "px");
$(window).trigger('resize');
},
handleUploadStart: function(filenames, channel_id) {
handleUploadStart: function(clientIds, channel_id) {
var draft = PostStore.getDraft(channel_id);
if (!draft) {
draft = {};
@@ -137,12 +137,12 @@ module.exports = React.createClass({
draft['previews'] = [];
}
draft['uploadsInProgress'] = draft['uploadsInProgress'].concat(filenames);
draft['uploadsInProgress'] = draft['uploadsInProgress'].concat(clientIds);
PostStore.storeDraft(channel_id, draft);
this.setState({uploadsInProgress: draft['uploadsInProgress']});
},
handleFileUploadComplete: function(filenames, channel_id) {
handleFileUploadComplete: function(filenames, clientIds, channel_id) {
var draft = PostStore.getDraft(channel_id);
if (!draft) {
draft = {};
@@ -152,18 +152,8 @@ module.exports = React.createClass({
}
// remove each finished file from uploads
for (var i = 0; i < filenames.length; i++) {
var filename = filenames[i];
// filenames returned by the server include a path while stored uploads only have the actual file name
var index = -1;
for (var j = 0; j < draft['uploadsInProgress'].length; j++) {
var upload = draft['uploadsInProgress'][j];
if (upload.indexOf(filename, upload.length - filename.length)) {
index = j;
break;
}
}
for (var i = 0; i < clientIds.length; i++) {
var index = draft['uploadsInProgress'].indexOf(clientIds[i]);
if (index != -1) {
draft['uploadsInProgress'].splice(index, 1);
@@ -178,20 +168,20 @@ module.exports = React.createClass({
handleUploadError: function(err) {
this.setState({ server_error: err });
},
removePreview: function(filename) {
removePreview: function(id) {
var previews = this.state.previews;
var uploadsInProgress = this.state.uploadsInProgress;
// this can be either an uploaded file or an in progress upload that we need to remove
var index = previews.indexOf(filename);
// id can either be the path of an uploaded file or the client id of an in progress upload
var index = previews.indexOf(id);
if (index !== -1) {
previews.splice(index, 1);
} else {
index = uploadsInProgress.indexOf(filename);
index = uploadsInProgress.indexOf(id);
if (index !== -1) {
uploadsInProgress.splice(index, 1);
this.refs.fileUpload.cancelUpload(filename);
this.refs.fileUpload.cancelUpload(id);
}
}