Continue move to redux
This commit is contained in:
50
src/redux/actions/release_version_actions.js
Normal file
50
src/redux/actions/release_version_actions.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import axios from 'axios';
|
||||
import * as Constants from '../../constants';
|
||||
import {createAction} from 'redux-starter-kit';
|
||||
|
||||
export const CLEAR_UI_UPGRADE = 'relver/clearUIUpgrade';
|
||||
export const clearUIUpgrade = () => {
|
||||
return {
|
||||
type: CLEAR_UI_UPGRADE,
|
||||
payload: null,
|
||||
};
|
||||
};
|
||||
|
||||
export const detectUIUpgrade = () => {
|
||||
return (dispatch, getState) => {
|
||||
axios
|
||||
.get(Constants.UI_RELEASES_URL)
|
||||
.then(response => {
|
||||
const state = getState();
|
||||
const appPlatform = state.common.AppPlatform;
|
||||
const version = state.common.Version;
|
||||
const data = response.data;
|
||||
|
||||
if (data.Versions &&
|
||||
data.Versions[appPlatform] &&
|
||||
(data.Versions[appPlatform].length > 0) &&
|
||||
(data.Versions[appPlatform][0] !== version)) {
|
||||
dispatch(setUIUpgradeData(data.Locations[appPlatform][data.Versions[appPlatform][0]]));
|
||||
} else {
|
||||
dispatch(clearUIUpgrade());
|
||||
}
|
||||
}).catch(() => {
|
||||
dispatch(clearUIUpgrade());
|
||||
//TODO Display error
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const SET_ACTIVE_RELEASE = 'relver/setActiveRelease';
|
||||
export const setActiveRelease = (release, version) => {
|
||||
return {
|
||||
type: SET_ACTIVE_RELEASE,
|
||||
payload: {
|
||||
release,
|
||||
version
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const setDismissUIUpgrade = createAction('relver/setDismissUIUpgrade');
|
||||
export const setUIUpgradeData = createAction('relver/setUIUpgradeData');
|
||||
Reference in New Issue
Block a user