{"size": 1096, "ext": "js", "max_stars_repo_path": "src/gear-preview/actions/update.js", "max_stars_repo_name": "stocky37/epicseven-gearchecker", "max_stars_repo_stars_event_min_datetime": "2019-01-19T10:19:56.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-22T08:55:08.000Z", "max_issues_repo_path": "src/gear-preview/actions/update.js", "max_issues_repo_name": "stocky37/epicseven-gearchecker", "max_issues_repo_issues_event_min_datetime": "2019-01-01T01:43:41.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-12T03:45:16.000Z", "max_forks_repo_path": "src/gear-preview/actions/update.js", "max_forks_repo_name": "stocky37/epicseven-tools", "max_forks_repo_forks_event_min_datetime": "2020-01-07T19:06:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-07T08:28:16.000Z"}
{"max_stars_count": 5, "max_issues_count": 78, "max_forks_count": 3, "avg_line_length": 32.2352941176, "max_line_length": 74, "alphanum_fraction": 0.7408759124}
import fetchHero from 'core/actions/requests/fetchHero';
import callApis from 'core/actions/util/callApis';
import getEquipRequest from 'gear-preview/selectors/getEquipRequest';
import loadingHeroInfo from './basic/loadingHeroInfo';
import loadingHeroInfoFail from './basic/loadingHeroInfoFail';
import loadingHeroInfoSuccess from './basic/loadingHeroInfoSuccess';
import fetchHeroBaseStats from './requests/fetchHeroBaseStats';
import fetchHeroEquippedStats from './requests/fetchHeroEquippedStats';

export default (stage = 0) => (dispatch, getState) => {
	dispatch(loadingHeroInfo());
	const {id, stars, awakening, gear} = getEquipRequest(getState());

	if (!id) {
		dispatch(loadingHeroInfoSuccess());
		return Promise.resolve();
	}

	const requests = [
		fetchHero(id),
		fetchHeroBaseStats(id, stars, awakening),
		fetchHeroEquippedStats(id, {
			stars,
			level: stars * 10,
			awakening,
			...gear,
		}),
	];

	return callApis(requests.filter((el, index) => index >= stage))(dispatch)
		.then(() => dispatch(loadingHeroInfoSuccess()))
		.catch(() => dispatch(loadingHeroInfoFail()));
};
