1
1
import {
2
2
ALERT_REPLAY , ALERT_TOGGLE , TEST_RESULT ,
3
- COMPLETE_PAGE , COMPLETE_CHAPTER , COMPLETE_TUTORIAL
3
+ COMPLETE_PAGE , COMPLETE_CHAPTER , COMPLETE_TUTORIAL ,
4
+ TUTORIAL_UPDATE
4
5
} from '../../actions/_types' ;
5
6
6
7
const _alert : CR . Alert = {
7
8
message : '' ,
8
9
open : false ,
9
10
action : '' ,
10
11
} ;
12
+ const open = {
13
+ open : true ,
14
+ pass : true ,
15
+ } ;
11
16
12
17
let current : CR . Alert = _alert ;
13
18
@@ -17,61 +22,58 @@ export default function alertReducer(
17
22
let statusBarAlert = < HTMLElement > document . getElementsByClassName ( 'cr-alert-replay' ) [ 0 ] ;
18
23
switch ( action . type ) {
19
24
case ALERT_REPLAY :
20
- return Object . assign ( { } , current , { open : true } ) ;
25
+ return Object . assign ( { } , current , open ) ;
21
26
case ALERT_TOGGLE :
22
27
return action . payload . alert || _alert ;
28
+ case TUTORIAL_UPDATE :
29
+ current = Object . assign ( { } , {
30
+ message : `run \`npm install --save-dev ${ action . payload . name } \`` ,
31
+ action : 'note' ,
32
+ duration : 4000 ,
33
+ } , open ) ;
34
+ return current ;
23
35
case TEST_RESULT :
24
36
let result = action . payload . result ;
25
37
if ( result . pass && result . change > 0 ) {
26
38
// Pass
27
39
statusBarAlert . style . color = '#73C990' ;
28
- current = {
40
+ current = Object . assign ( { } , {
29
41
message : result . msg ,
30
- open : true ,
31
- action : 'pass' ,
32
42
duration : result . duration || 1500 ,
33
- } ;
43
+ } , open ) ;
34
44
return current ;
35
45
} else if ( result . pass === false && result . change < 1 ) {
36
46
// Fail
37
47
statusBarAlert . style . color = '#FF4081' ;
38
- current = {
48
+ current = Object . assign ( { } , {
39
49
message : result . msg ,
40
- open : true ,
41
50
action : 'fail' ,
42
51
duration : result . duration || 2500 ,
43
- } ;
52
+ } , open ) ;
44
53
return current ;
45
54
}
46
55
// Alert
47
56
statusBarAlert . style . color = '#9DA5B4' ;
48
- current = {
57
+ current = Object . assign ( { } , {
49
58
message : result . msg ,
50
- open : true ,
51
59
action : 'note' ,
52
60
duration : result . duration || 2500 ,
53
- } ;
61
+ } , open ) ;
54
62
return current ;
55
63
case COMPLETE_PAGE :
56
- current = {
64
+ current = Object . assign ( { } , {
57
65
message : `Page ${ action . payload . position . page + 1 } Complete` ,
58
- open : true ,
59
- action : 'pass' ,
60
- } ;
66
+ } , open ) ;
61
67
return current ;
62
68
case COMPLETE_CHAPTER :
63
- current = {
69
+ current = Object . assign ( { } , {
64
70
message : `Chapter ${ action . payload . chapter + 1 } Complete` ,
65
- open : true ,
66
- action : 'pass' ,
67
- } ;
71
+ } , open ) ;
68
72
return current ;
69
73
case COMPLETE_TUTORIAL :
70
- current = {
74
+ current = Object . assign ( { } , {
71
75
message : 'Tutorial Complete' ,
72
- open : true ,
73
- action : 'pass' ,
74
- } ;
76
+ } , open ) ;
75
77
return current ;
76
78
default :
77
79
return alert ;
0 commit comments