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');
|
||||
53
src/redux/reducers/release_version_reducer.js
Normal file
53
src/redux/reducers/release_version_reducer.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import {createReducer} from 'redux-starter-kit';
|
||||
import * as Actions from '../actions/release_version_actions';
|
||||
import * as Constants from '../../constants';
|
||||
|
||||
const versionLookup = Constants.RELEASE_TYPES.map(k=> {
|
||||
return {
|
||||
[k]: ['unavailable']
|
||||
};
|
||||
}).reduce((map, obj) => {
|
||||
return {
|
||||
...map,
|
||||
...obj,
|
||||
};
|
||||
});
|
||||
|
||||
export const releaseVersionReducer = createReducer({
|
||||
LocationsLookup: {},
|
||||
Release: 2,
|
||||
UpgradeAvailable: false,
|
||||
UpgradeDismissed: false,
|
||||
Version: -1,
|
||||
VersionLookup: versionLookup,
|
||||
}, {
|
||||
[Actions.CLEAR_UI_UPGRADE]: state => {
|
||||
return {
|
||||
...state,
|
||||
UpgradeAvailable: false,
|
||||
UpgradeDismissed: false,
|
||||
UpgradeData: null,
|
||||
};
|
||||
},
|
||||
[Actions.SET_ACTIVE_RELEASE]: (state, action) => {
|
||||
return {
|
||||
...state,
|
||||
Release: action.payload.release,
|
||||
Version: action.payload.version
|
||||
};
|
||||
},
|
||||
[Actions.setDismissUIUpgrade]: (state, action) => {
|
||||
return {
|
||||
...state,
|
||||
UpgradeDismissed: action.payload,
|
||||
};
|
||||
},
|
||||
[Actions.setUIUpgradeData]: (state, action) => {
|
||||
return {
|
||||
...state,
|
||||
UpgradeAvailable: true,
|
||||
UpgradeData: action.payload,
|
||||
UpgradeDismissed: false,
|
||||
};
|
||||
}
|
||||
});
|
||||
@@ -1,17 +1,20 @@
|
||||
import {configureStore, createReducer, getDefaultMiddleware} from 'redux-starter-kit';
|
||||
import {mountReducer} from '../reducers/mount_reducer';
|
||||
import {releaseVersionReducer} from '../reducers/release_version_reducer';
|
||||
|
||||
export default function createAppStore(platform, appPlatform) {
|
||||
export default function createAppStore(platform, appPlatform, version) {
|
||||
const createCommonReducer = () => {
|
||||
return createReducer({
|
||||
AppPlatform: appPlatform,
|
||||
Platform: platform,
|
||||
Version: version,
|
||||
}, {});
|
||||
};
|
||||
|
||||
const reducer = {
|
||||
common: createCommonReducer(platform, appPlatform),
|
||||
common: createCommonReducer(platform, appPlatform, version),
|
||||
mounts: mountReducer,
|
||||
relver: releaseVersionReducer,
|
||||
};
|
||||
|
||||
const middleware = [...getDefaultMiddleware()];
|
||||
|
||||
Reference in New Issue
Block a user