UNPKG

1.36 kBJavaScriptView Raw
1import _includes from "lodash/fp/includes";
2import _find from "lodash/fp/find";
3export default function stars(config) {
4 return (currentStars = 0, action, state) => {
5 switch (action.type) {
6 case 'answer':
7 {
8 const answerAction = action;
9 return !answerAction.payload.instructions && answerAction.payload.isCorrect ? currentStars + config.starsPerCorrectAnswer : currentStars;
10 }
11
12 case 'clue':
13 {
14 const requestedClueAction = action;
15 const slideRef = requestedClueAction.payload.content.ref;
16 return _includes(slideRef, state.requestedClues) ? currentStars : currentStars + config.starsPerAskingClue;
17 }
18
19 case 'resource':
20 {
21 const contentResourceViewedAction = action;
22 const contentRef = contentResourceViewedAction.payload.content.ref;
23 const contentType = contentResourceViewedAction.payload.content.type;
24 const contentResourceAlreadyViewed = Boolean(_find({
25 type: contentType,
26 ref: contentRef
27 }, state.viewedResources));
28
29 if (contentResourceAlreadyViewed) {
30 return currentStars;
31 }
32
33 return currentStars + config.starsPerResourceViewed;
34 }
35
36 default:
37 return currentStars;
38 }
39 };
40}
41//# sourceMappingURL=stars.js.map
\No newline at end of file