Files
flood/client/source/scripts/actions/ClientActions.js
2016-03-19 12:46:11 +01:00

79 lines
1.8 KiB
JavaScript

import axios from 'axios';
import AppDispatcher from '../dispatcher/AppDispatcher';
import ActionTypes from '../constants/ActionTypes';
const ClientActions = {
fetchTransferData: () => {
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: (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: (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;