Move instances of Client.uploadFile() in components to an action (#5165)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
dbfd93daa7
Коммит
9cc37e6918
26
webapp/actions/file_actions.jsx
Обычный файл
26
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import 'jquery-dragster/jquery.dragster.js';
|
import 'jquery-dragster/jquery.dragster.js';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import Client from 'client/web_client.jsx';
|
|
||||||
import Constants from 'utils/constants.jsx';
|
import Constants from 'utils/constants.jsx';
|
||||||
import ChannelStore from 'stores/channel_store.jsx';
|
import ChannelStore from 'stores/channel_store.jsx';
|
||||||
import DelayedAction from 'utils/delayed_action.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 {intlShape, injectIntl, defineMessages} from 'react-intl';
|
||||||
|
|
||||||
|
import {uploadFile} from 'actions/file_actions.jsx';
|
||||||
|
|
||||||
const holders = defineMessages({
|
const holders = defineMessages({
|
||||||
limited: {
|
limited: {
|
||||||
id: 'file_upload.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
|
// generate a unique id that can be used by other components to refer back to this upload
|
||||||
const clientId = Utils.generateId();
|
const clientId = Utils.generateId();
|
||||||
|
|
||||||
const request = Client.uploadFile(files[i],
|
const request = uploadFile(
|
||||||
files[i].name,
|
files[i],
|
||||||
channelId,
|
files[i].name,
|
||||||
clientId,
|
channelId,
|
||||||
this.fileUploadSuccess.bind(this, channelId),
|
clientId,
|
||||||
this.fileUploadFail.bind(this, clientId, channelId)
|
this.fileUploadSuccess.bind(this, channelId),
|
||||||
);
|
this.fileUploadFail.bind(this, clientId)
|
||||||
|
);
|
||||||
|
|
||||||
const requests = this.state.requests;
|
const requests = this.state.requests;
|
||||||
requests[clientId] = request;
|
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 name = formatMessage(holders.pasted) + d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + hour + '-' + min + '.' + ext;
|
||||||
|
|
||||||
const request = Client.uploadFile(file,
|
const request = uploadFile(
|
||||||
|
file,
|
||||||
name,
|
name,
|
||||||
channelId,
|
channelId,
|
||||||
clientId,
|
clientId,
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user