Files
flood/client/source/scripts/actions/ClientActions.js
T
2016-02-06 01:22:28 -08:00

79 lines
1.8 KiB
JavaScript

import axios from 'axios';
import AppDispatcher from '../dispatcher/AppDispatcher';
import ActionTypes from '../constants/ActionTypes';
const ClientActions = {
fetchTransferData: function() {
return axios.get('/client/stats')
.then((json = {}) => {
return json.data;
})
.then((transferData) => {
AppDispatcher.dispatchServerAction({
type: ActionTypes.CLIENT_FETCH_TRANSFER_DATA_SUCCESS,
data: {
transferData
}
});
})
.catch((error) => {
AppDispatcher.dispatchServerAction({
type: ActionTypes.CLIENT_FETCH_TRANSFER_DATA_ERROR,
data: {
error
}
});
});
},
fetchTransferHistory: function(opts) {
return axios.get('/client/history', {
params: opts
})
.then((json = {}) => {
return json.data;
})
.then((data) => {
AppDispatcher.dispatchServerAction({
type: ActionTypes.CLIENT_FETCH_TRANSFER_HISTORY_SUCCESS,
data
});
})
.catch((error) => {
AppDispatcher.dispatchServerAction({
type: ActionTypes.CLIENT_FETCH_TRANSFER_HISTORY_ERROR,
error
});
})
},
setThrottle: function(direction, throttle) {
return axios.put('/client/settings/speed-limits', {
direction,
throttle
})
.then((json = {}) => {
return json.data;
})
.then((transferData) => {
AppDispatcher.dispatchServerAction({
type: ActionTypes.CLIENT_SET_THROTTLE_SUCCESS,
data: {
transferData
}
});
})
.catch((error) => {
AppDispatcher.dispatchServerAction({
type: ActionTypes.CLIENT_SET_THROTTLE_ERROR,
data: {
error
}
});
});
}
};
export default ClientActions;