* fix(layout): Fix Settings layout in firefox * chore(availableForHire): Remove available for hire setting * feat(helpers): Use helper components for Settings layout * fix(map): Fix undefined lang requested * feat(settings): Expand Settings page functionality * chore(pledge): Remove pledge from Settings * fix(about): Adjust AboutSettings layout * fix(portfolio): Improve PortfolioSettings layout * fix(email): Improve EmailSettings layout * fix(settings): Align save buttons with form fields * fix(AHP): Format AHP * fix(DangerZone): Adjust DangerZone layout * fix(projectSettings): Change Button Copy * fix(CertSettings): Fix certificate claim logic * chore(lint): Lint
88 lines
2.3 KiB
JavaScript
88 lines
2.3 KiB
JavaScript
import { Observable } from 'rx';
|
|
import { combineEpics, ofType } from 'redux-epic';
|
|
import debug from 'debug';
|
|
|
|
import {
|
|
types,
|
|
|
|
createErrorObservable,
|
|
delayedRedirect,
|
|
|
|
fetchChallengeCompleted,
|
|
fetchChallengesCompleted
|
|
} from './';
|
|
import { isChallengeLoaded } from '../entities/index.js';
|
|
|
|
import { shapeChallenges } from './utils';
|
|
import { types as challenge } from '../routes/Challenges/redux';
|
|
import { langSelector } from '../Router/redux';
|
|
|
|
const isDev = debug.enabled('fcc:*');
|
|
|
|
export function fetchChallengeEpic(actions, { getState }, { services }) {
|
|
return actions::ofType(challenge.onRouteChallenges)
|
|
.filter(({ payload }) => !isChallengeLoaded(getState(), payload))
|
|
.flatMapLatest(({ payload: params }) => {
|
|
const options = {
|
|
service: 'map',
|
|
params
|
|
};
|
|
return services.readService$(options)
|
|
.retry(3)
|
|
.map(({ entities, ...rest }) => ({
|
|
entities: shapeChallenges(entities, isDev),
|
|
...rest
|
|
}))
|
|
.flatMap(({ entities, result, redirect } = {}) => {
|
|
const actions = [
|
|
fetchChallengeCompleted({
|
|
entities,
|
|
currentChallenge: result.challenge,
|
|
challenge: entities.challenge[result.challenge],
|
|
result
|
|
}),
|
|
redirect ? delayedRedirect(redirect) : null
|
|
];
|
|
return Observable.from(actions).filter(Boolean);
|
|
})
|
|
.catch(createErrorObservable);
|
|
});
|
|
}
|
|
|
|
export function fetchChallengesEpic(
|
|
actions,
|
|
{ getState },
|
|
{ services }
|
|
) {
|
|
return actions::ofType(
|
|
types.appMounted,
|
|
types.updateChallenges
|
|
)
|
|
.flatMapLatest(() => {
|
|
const lang = langSelector(getState());
|
|
const options = {
|
|
params: { lang },
|
|
service: 'map'
|
|
};
|
|
return services.readService$(options)
|
|
.retry(3)
|
|
.map(({ entities, ...res }) => ({
|
|
entities: shapeChallenges(
|
|
entities,
|
|
isDev
|
|
),
|
|
...res
|
|
}))
|
|
.map(({ entities, result } = {}) => {
|
|
return fetchChallengesCompleted(
|
|
entities,
|
|
result
|
|
);
|
|
})
|
|
.startWith({ type: types.fetchChallenges.start })
|
|
.catch(createErrorObservable);
|
|
});
|
|
}
|
|
|
|
export default combineEpics(fetchChallengeEpic, fetchChallengesEpic);
|