Skip to content

Commit 50c5bd0

Browse files
committed
Merge branch 'dev'
2 parents 47d7d59 + f509ff5 commit 50c5bd0

File tree

3 files changed

+53
-63
lines changed

3 files changed

+53
-63
lines changed

lib/reducers/alert/index.js

+20-23
Original file line numberDiff line numberDiff line change
@@ -7,65 +7,62 @@ var _alert = {
77
};
88
var open = {
99
open: true,
10-
pass: true,
10+
action: 'pass',
1111
};
1212
var current = _alert;
13+
function setAlert(options) {
14+
current = Object.assign({}, open, options);
15+
return current;
16+
}
1317
function alertReducer(alert, action) {
1418
if (alert === void 0) { alert = _alert; }
1519
var statusBarAlert = document.getElementsByClassName('cr-alert-replay')[0];
1620
switch (action.type) {
1721
case _types_1.ALERT_REPLAY:
18-
return Object.assign({}, current, open);
22+
return setAlert(current);
1923
case _types_1.ALERT_TOGGLE:
2024
return action.payload.alert || _alert;
2125
case _types_1.TUTORIAL_UPDATE:
22-
current = Object.assign({}, {
26+
return setAlert({
2327
message: "run `npm install --save-dev " + action.payload.name + "`",
2428
action: 'note',
2529
duration: 4000,
26-
}, open);
27-
return current;
30+
});
2831
case _types_1.TEST_RESULT:
2932
var result = action.payload.result;
3033
if (result.pass && result.change > 0) {
3134
statusBarAlert.style.color = '#73C990';
32-
current = Object.assign({}, {
35+
return setAlert({
3336
message: result.msg,
3437
duration: result.duration || 1500,
35-
}, open);
36-
return current;
38+
});
3739
}
3840
else if (result.pass === false && result.change < 1) {
3941
statusBarAlert.style.color = '#FF4081';
40-
current = Object.assign({}, {
42+
return setAlert({
4143
message: result.msg,
4244
action: 'fail',
4345
duration: result.duration || 2500,
44-
}, open);
45-
return current;
46+
});
4647
}
4748
statusBarAlert.style.color = '#9DA5B4';
48-
current = Object.assign({}, {
49+
return setAlert({
4950
message: result.msg,
5051
action: 'note',
5152
duration: result.duration || 2500,
52-
}, open);
53-
return current;
53+
});
5454
case _types_1.COMPLETE_PAGE:
55-
current = Object.assign({}, {
55+
return setAlert({
5656
message: "Page " + (action.payload.position.page + 1) + " Complete",
57-
}, open);
58-
return current;
57+
});
5958
case _types_1.COMPLETE_CHAPTER:
60-
current = Object.assign({}, {
59+
return setAlert({
6160
message: "Chapter " + (action.payload.chapter + 1) + " Complete",
62-
}, open);
63-
return current;
61+
});
6462
case _types_1.COMPLETE_TUTORIAL:
65-
current = Object.assign({}, {
63+
return setAlert({
6664
message: 'Tutorial Complete',
67-
}, open);
68-
return current;
65+
});
6966
default:
7067
return alert;
7168
}

src/components/Alert/_alert.less

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
@import "ui-variables";
22

3-
.cr-alert.pass {
3+
.cr-alert {
44
button {
5+
position: relative;
56
span {
6-
color: @background-color-success;
7+
position: absolute;
8+
top: -8px;
79
}
810
}
911
}
10-
.cr-alert.fail {
11-
button {
12-
span {
13-
color: @background-color-error;
14-
}
15-
}
12+
.cr-alert.pass button span {
13+
color: @background-color-success;
1614
}
17-
.cr-alert.note {
18-
button {
19-
span {
20-
color: @background-color-info;
21-
}
22-
}
15+
.cr-alert.fail button span {
16+
color: @background-color-error;
17+
}
18+
.cr-alert.note button span {
19+
color: @background-color-info;
2320
}
24-
2521
.cr-alert-replay {
2622
display: inline-block;
27-
margin-left: 10px;
28-
margin-right: 10px;
23+
margin: 0 10px;
2924
}

src/reducers/alert/index.ts

+21-23
Original file line numberDiff line numberDiff line change
@@ -11,70 +11,68 @@ const _alert: CR.Alert = {
1111
};
1212
const open = {
1313
open: true,
14-
pass: true,
14+
action: 'pass',
1515
};
1616

1717
let current: CR.Alert = _alert;
1818

19+
function setAlert(options) {
20+
current = Object.assign({}, open, options);
21+
return current;
22+
}
23+
1924
export default function alertReducer(
2025
alert = _alert, action: Action
2126
): CR.Alert {
2227
let statusBarAlert = <HTMLElement>document.getElementsByClassName('cr-alert-replay')[0];
2328
switch (action.type) {
2429
case ALERT_REPLAY:
25-
return Object.assign({}, current, open);
30+
return setAlert(current);
2631
case ALERT_TOGGLE:
2732
return action.payload.alert || _alert;
2833
case TUTORIAL_UPDATE:
29-
current = Object.assign({}, {
34+
return setAlert({
3035
message: `run \`npm install --save-dev ${action.payload.name}\``,
3136
action: 'note',
3237
duration: 4000,
33-
}, open);
34-
return current;
38+
});
3539
case TEST_RESULT:
3640
let result = action.payload.result;
3741
if (result.pass && result.change > 0) {
3842
// Pass
3943
statusBarAlert.style.color = '#73C990';
40-
current = Object.assign({}, {
44+
return setAlert({
4145
message: result.msg,
4246
duration: result.duration || 1500,
43-
}, open);
44-
return current;
47+
});
4548
} else if (result.pass === false && result.change < 1) {
4649
// Fail
4750
statusBarAlert.style.color = '#FF4081';
48-
current = Object.assign({}, {
51+
return setAlert({
4952
message: result.msg,
5053
action: 'fail',
5154
duration: result.duration || 2500,
52-
}, open);
53-
return current;
55+
});
5456
}
5557
// Alert
5658
statusBarAlert.style.color = '#9DA5B4';
57-
current = Object.assign({}, {
59+
return setAlert({
5860
message: result.msg,
5961
action: 'note',
6062
duration: result.duration || 2500,
61-
}, open);
62-
return current;
63+
});
6364
case COMPLETE_PAGE:
64-
current = Object.assign({}, {
65+
return setAlert({
6566
message: `Page ${action.payload.position.page + 1} Complete`,
66-
}, open);
67-
return current;
67+
});
6868
case COMPLETE_CHAPTER:
69-
current = Object.assign({}, {
69+
return setAlert({
7070
message: `Chapter ${action.payload.chapter + 1} Complete`,
71-
}, open);
72-
return current;
71+
});
7372
case COMPLETE_TUTORIAL:
74-
current = Object.assign({}, {
73+
return setAlert({
7574
message: 'Tutorial Complete',
76-
}, open);
77-
return current;
75+
});
7876
default:
7977
return alert;
8078
}

0 commit comments

Comments
 (0)