Add random compliment on challenge completion
This commit is contained in:
31
client/sagas/completion-saga.js
Normal file
31
client/sagas/completion-saga.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Observable } from 'rx';
|
||||
import types from '../../common/app/routes/challenges/redux/types';
|
||||
import { makeToast } from '../../common/app/redux/actions';
|
||||
|
||||
import { randomCompliment } from '../../common/app/utils/get-words';
|
||||
/*
|
||||
import {
|
||||
updateOutput,
|
||||
checkChallenge,
|
||||
updateTests
|
||||
} from '../../common/app/routes/challenges/redux/actions';
|
||||
*/
|
||||
|
||||
export default function completionSaga(actions$, getState) {
|
||||
return actions$
|
||||
.filter(({ type }) => (
|
||||
type === types.checkChallenge
|
||||
))
|
||||
.flatMap(() => {
|
||||
const { tests } = getState().challengesApp;
|
||||
if (tests.length > 1 && tests.every(test => test.pass && !test.err)) {
|
||||
return Observable.of(
|
||||
makeToast({
|
||||
type: 'success',
|
||||
message: randomCompliment()
|
||||
})
|
||||
);
|
||||
}
|
||||
return Observable.just(null);
|
||||
});
|
||||
}
|
@@ -2,9 +2,8 @@ import Rx, { Observable, Subject } from 'rx';
|
||||
import loopProtect from 'loop-protect';
|
||||
import types from '../../common/app/routes/challenges/redux/types';
|
||||
import {
|
||||
updateOutput
|
||||
} from '../../common/app/routes/challenges/redux/actions';
|
||||
import {
|
||||
updateOutput,
|
||||
checkChallenge,
|
||||
updateTests
|
||||
} from '../../common/app/routes/challenges/redux/actions';
|
||||
|
||||
@@ -108,9 +107,13 @@ export default function frameSaga(actions$, getState, { window, document }) {
|
||||
runTests$.flatMap(() => {
|
||||
const { frame } = getFrameDocument(document, testId);
|
||||
const { tests } = getState().challengesApp;
|
||||
const postTests = Observable.of(
|
||||
updateOutput('// tests completed'),
|
||||
checkChallenge()
|
||||
).delay(250);
|
||||
return frame.__runTests$(tests)
|
||||
.map(updateTests)
|
||||
.concat(Observable.just(updateOutput('// tests completed')).delay(250));
|
||||
.concat(postTests);
|
||||
}),
|
||||
result$
|
||||
);
|
||||
|
@@ -5,6 +5,7 @@ import hardGoToSaga from './hard-go-to-saga';
|
||||
import windowSaga from './window-saga';
|
||||
import executeChallengeSaga from './execute-challenge-saga';
|
||||
import frameSaga from './frame-saga';
|
||||
import completionSaga from './completion-saga';
|
||||
import codeStorageSaga from './code-storage-saga';
|
||||
|
||||
export default [
|
||||
@@ -15,5 +16,6 @@ export default [
|
||||
windowSaga,
|
||||
executeChallengeSaga,
|
||||
frameSaga,
|
||||
completionSaga,
|
||||
codeStorageSaga
|
||||
];
|
||||
|
Reference in New Issue
Block a user