mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Move instances of Client.uploadFile() in components to an action (#5165)
This commit is contained in:
committed by
Joram Wilander
parent
dbfd93daa7
commit
9cc37e6918
26
webapp/actions/file_actions.jsx
Normal file
26
webapp/actions/file_actions.jsx
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user