mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-13 01:07:42 -05:00
78 lines
1.7 KiB
JavaScript
78 lines
1.7 KiB
JavaScript
import axios from "axios";
|
|
//import { browserHistory } from "react-router"
|
|
import * as types from "./system-constants";
|
|
import { push } from 'connected-react-router';
|
|
|
|
const FETCH_SUCCESS_STATISTIC = "FETCH_SUCCESS_STATISTIC"
|
|
|
|
function beginFetchSystem() {
|
|
return { type: types.FETCH_SYSTEM };
|
|
}
|
|
|
|
function fetchSystemSuccess(data) {
|
|
return { type: types.FETCH_SUCCESS_SYSTEM,
|
|
data };
|
|
}
|
|
|
|
function fetchSystemError(data) {
|
|
return { type: types.FETCH_ERROR_SYSTEM,
|
|
data };
|
|
}
|
|
|
|
|
|
function makeUserRequest(method, data, api = "/login") {
|
|
// returns a Promise
|
|
return axios({
|
|
method: method,
|
|
url: api,
|
|
data: data
|
|
});
|
|
}
|
|
|
|
export function changeUrl(url) {
|
|
return dispatch => {
|
|
dispatch(push(url));
|
|
};
|
|
}
|
|
|
|
// Example of an Async Action Creator
|
|
// http://redux.js.org/docs/advanced/AsyncActions.html
|
|
|
|
function shouldFetchSystems(state, subreddit) {
|
|
if ((!state.system.items) || (state.system.items.length <1)) {
|
|
return true
|
|
} else if (state.system.isWaiting) {
|
|
return false
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function fetchSystems() {
|
|
return (dispatch, getState) => {
|
|
if (shouldFetchSystems(getState())) {
|
|
dispatch(beginFetchSystem());
|
|
|
|
return axios
|
|
.get(backend_server + "/systems")
|
|
.then(response => {
|
|
if (response.data.success) {
|
|
dispatch(fetchSystemSuccess(response.data.systems));
|
|
} else {
|
|
dispatch(fetchSystemError());
|
|
let registerMessage = response.data.message;
|
|
return registerMessage;
|
|
}
|
|
})
|
|
.catch(response => {
|
|
if (response instanceof Error) {
|
|
// Something happened in setting up the request that triggered an Error
|
|
console.log("Error", response.message);
|
|
}
|
|
});
|
|
};
|
|
};
|
|
}
|