Update users currentChallengeId when on a new challenge (#101)
Closes #94
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
858608e307
commit
5dea8b58d0
@ -39,6 +39,8 @@ export const isSignedInSelector = state => state[ns].isSignedIn;
|
|||||||
export const userSelector = state => state[ns].user || {};
|
export const userSelector = state => state[ns].user || {};
|
||||||
export const completedChallengesSelector = state =>
|
export const completedChallengesSelector = state =>
|
||||||
state[ns].user.completedChallenges || [];
|
state[ns].user.completedChallenges || [];
|
||||||
|
export const currentChallengeIdSelector = state =>
|
||||||
|
userSelector(state).currentChallengeId || '';
|
||||||
|
|
||||||
export const reducer = handleActions(
|
export const reducer = handleActions(
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
import { ofType } from 'redux-observable';
|
||||||
|
|
||||||
|
import { types } from './';
|
||||||
|
import { filter, switchMap, catchError, mapTo } from 'rxjs/operators';
|
||||||
|
import {
|
||||||
|
isSignedInSelector,
|
||||||
|
currentChallengeIdSelector
|
||||||
|
} from '../../../redux/app';
|
||||||
|
import { postJSON$ } from '../utils/ajax-stream';
|
||||||
|
import { _csrf } from '../../../redux/cookieVaules';
|
||||||
|
import { of } from 'rxjs/observable/of';
|
||||||
|
|
||||||
|
function currentChallengeEpic(action$, { getState }) {
|
||||||
|
return action$.pipe(
|
||||||
|
ofType(types.challengeMounted),
|
||||||
|
filter(() => isSignedInSelector(getState())),
|
||||||
|
filter(({ payload }) => payload !== currentChallengeIdSelector(getState())),
|
||||||
|
switchMap(({ payload }) =>
|
||||||
|
postJSON$('/external/update-my-current-challenge', {
|
||||||
|
currentChallengeId: payload,
|
||||||
|
_csrf
|
||||||
|
})
|
||||||
|
),
|
||||||
|
mapTo({ type: 'currentChallengeUpdateComplete' }),
|
||||||
|
catchError(() => of({ type: 'current-challenge-update-error' }))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default currentChallengeEpic;
|
@ -8,6 +8,7 @@ import executeChallengeEpic from './execute-challenge-epic';
|
|||||||
import codeLockEpic from './code-lock-epic';
|
import codeLockEpic from './code-lock-epic';
|
||||||
import createQuestionEpic from './create-question-epic';
|
import createQuestionEpic from './create-question-epic';
|
||||||
import codeStorageEpic from './code-storage-epic';
|
import codeStorageEpic from './code-storage-epic';
|
||||||
|
import currentChallengeEpic from './current-challenge-epic';
|
||||||
|
|
||||||
const ns = 'challenge';
|
const ns = 'challenge';
|
||||||
export const backendNS = 'backendChallenge';
|
export const backendNS = 'backendChallenge';
|
||||||
@ -37,7 +38,8 @@ export const epics = [
|
|||||||
completionEpic,
|
completionEpic,
|
||||||
createQuestionEpic,
|
createQuestionEpic,
|
||||||
executeChallengeEpic,
|
executeChallengeEpic,
|
||||||
codeStorageEpic
|
codeStorageEpic,
|
||||||
|
currentChallengeEpic
|
||||||
];
|
];
|
||||||
|
|
||||||
export const types = createTypes(
|
export const types = createTypes(
|
||||||
|
Reference in New Issue
Block a user