summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2017-01-23 15:23:14 +0100
committerJoram Wilander <jwawilander@gmail.com>2017-01-23 09:23:14 -0500
commit9cc37e6918fcbf53744612704ab53bce7290c7fd (patch)
tree6dcf538ba4af2988b0cd9b4aa9df3c64fb30af78
parentdbfd93daa75a0998bc8645245f9cc1ad77f3cadd (diff)
downloadchat-9cc37e6918fcbf53744612704ab53bce7290c7fd.tar.gz
chat-9cc37e6918fcbf53744612704ab53bce7290c7fd.tar.bz2
chat-9cc37e6918fcbf53744612704ab53bce7290c7fd.zip
Move instances of Client.uploadFile() in components to an action (#5165)
-rw-r--r--webapp/actions/file_actions.jsx26
-rw-r--r--webapp/components/file_upload.jsx21
2 files changed, 38 insertions, 9 deletions
diff --git a/webapp/actions/file_actions.jsx b/webapp/actions/file_actions.jsx
new file mode 100644
index 000000000..0399a2c28
--- /dev/null
+++ b/webapp/actions/file_actions.jsx
@@ -0,0 +1,26 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import * as AsyncClient from 'utils/async_client.jsx';
+import Client from 'client/web_client.jsx';
+
+export function uploadFile(file, name, channelId, clientId, success, error) {
+ Client.uploadFile(
+ file,
+ name,
+ channelId,
+ clientId,
+ (data) => {
+ if (success) {
+ success(data);
+ }
+ },
+ (err) => {
+ AsyncClient.dispatchError(err, 'uploadFile');
+
+ if (error) {
+ error(err);
+ }
+ }
+ );
+}
diff --git a/webapp/components/file_upload.jsx b/webapp/components/file_upload.jsx
index 36beb8c91..a821fedab 100644
--- a/webapp/components/file_upload.jsx
+++ b/webapp/components/file_upload.jsx
@@ -4,7 +4,6 @@
import $ from 'jquery';
import 'jquery-dragster/jquery.dragster.js';
import ReactDOM from 'react-dom';
-import Client from 'client/web_client.jsx';
import Constants from 'utils/constants.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import DelayedAction from 'utils/delayed_action.jsx';
@@ -13,6 +12,8 @@ import * as Utils from 'utils/utils.jsx';
import {intlShape, injectIntl, defineMessages} from 'react-intl';
+import {uploadFile} from 'actions/file_actions.jsx';
+
const holders = defineMessages({
limited: {
id: 'file_upload.limited',
@@ -89,13 +90,14 @@ class FileUpload extends React.Component {
// generate a unique id that can be used by other components to refer back to this upload
const clientId = Utils.generateId();
- const request = Client.uploadFile(files[i],
- files[i].name,
- channelId,
- clientId,
- this.fileUploadSuccess.bind(this, channelId),
- this.fileUploadFail.bind(this, clientId, channelId)
- );
+ const request = uploadFile(
+ files[i],
+ files[i].name,
+ channelId,
+ clientId,
+ this.fileUploadSuccess.bind(this, channelId),
+ this.fileUploadFail.bind(this, clientId)
+ );
const requests = this.state.requests;
requests[clientId] = request;
@@ -271,7 +273,8 @@ class FileUpload extends React.Component {
const name = formatMessage(holders.pasted) + d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + hour + '-' + min + '.' + ext;
- const request = Client.uploadFile(file,
+ const request = uploadFile(
+ file,
name,
channelId,
clientId,