117 lines
3.7 KiB
JavaScript
117 lines
3.7 KiB
JavaScript
import axios from 'axios';
|
|
import * as Constants from '../../constants';
|
|
import {createAction} from 'redux-starter-kit';
|
|
import {setApplicationReady} from '../actions/common_actions';
|
|
|
|
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 loadReleases = () => {
|
|
return (dispatch, getState) => {
|
|
const dispatchActions = (locationsLookup, versionLookup)=> {
|
|
const state = getState().relver;
|
|
const latestVersion = versionLookup[Constants.RELEASE_TYPES[state.Release]].length - 1;
|
|
let version = state.Version;
|
|
if ((version === -1) || !versionLookup[Constants.RELEASE_TYPES[state.Release]][version]) {
|
|
version = latestVersion;
|
|
}
|
|
|
|
dispatch(setReleaseData(locationsLookup, versionLookup));
|
|
if (version !== state.Version) {
|
|
dispatch(setActiveRelease(state.Release, version));
|
|
}
|
|
dispatch(setReleaseUpgradeAvailable((version !== latestVersion)));
|
|
dispatch(setApplicationReady(true));
|
|
};
|
|
|
|
axios
|
|
.get(Constants.RELEASES_URL)
|
|
.then(response => {
|
|
const appPlatform = getState().common.AppPlatform;
|
|
const versionLookup = {
|
|
Release: response.data.Versions.Release[appPlatform],
|
|
RC: response.data.Versions.RC[appPlatform],
|
|
Beta: response.data.Versions.Beta[appPlatform],
|
|
Alpha: response.data.Versions.Alpha[appPlatform],
|
|
};
|
|
const locationsLookup = {
|
|
...response.data.Locations[appPlatform],
|
|
};
|
|
|
|
localStorage.setItem('releases', JSON.stringify({
|
|
LocationsLookup: locationsLookup,
|
|
VersionLookup: versionLookup
|
|
}));
|
|
dispatchActions(locationsLookup, versionLookup);
|
|
}).catch(error => {
|
|
const releases = window.localStorage.getItem('releases');
|
|
if (releases && (releases.length > 0)) {
|
|
const obj = JSON.parse(releases);
|
|
const locationsLookup = obj.LocationsLookup;
|
|
const versionLookup = obj.VersionLookup;
|
|
|
|
dispatchActions(locationsLookup, versionLookup);
|
|
} else {
|
|
//this.setErrorState(error, null, true);
|
|
//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 SET_RELEASE_DATA = 'relver/setReleaseData';
|
|
export const setReleaseData = (locationsLookup, versionLookup)=> {
|
|
return {
|
|
type: SET_RELEASE_DATA,
|
|
payload: {
|
|
locations: locationsLookup,
|
|
versions: versionLookup,
|
|
}
|
|
}
|
|
};
|
|
|
|
export const setReleaseUpgradeAvailable = createAction('relver/setReleaseUpgradeAvailable');
|
|
export const setUIUpgradeData = createAction('relver/setUIUpgradeData'); |