@@ -5,19 +5,22 @@ import {
55 COUNT_DOWN_ONE_SECOND ,
66 START_TIMER ,
77 STOP_TIMER ,
8+ ADD_NOTIFICATION ,
89} from '@state/actions/timerActions'
910import { Time } from '../../time'
1011
1112export type IStateTimer = {
1213 readonly counting : boolean
1314 readonly timeLeft : Time
1415 readonly duration : Time
16+ readonly notifications : ReadonlyArray < Notification >
1517}
1618
1719const initialState : IStateTimer = {
1820 counting : false ,
1921 timeLeft : new Time ( ) ,
2022 duration : new Time ( ) ,
23+ notifications : [ ] ,
2124}
2225
2326const cachedSettings = JSON . parse (
@@ -37,7 +40,7 @@ if (cachedSettings) {
3740}
3841
3942export const timerReducers = (
40- state = Object . assign ( { } , initialState , cachedSettings ) ,
43+ state : IStateTimer = Object . assign ( { } , initialState , cachedSettings ) ,
4144 action : RootAction
4245) => {
4346 switch ( action . type ) {
@@ -50,10 +53,13 @@ export const timerReducers = (
5053 } )
5154
5255 case START_TIMER :
56+ state . notifications . forEach ( notification => notification . close ( ) )
57+
5358 return Object . assign ( { } , state , {
5459 timeLeft :
5560 state . timeLeft . toSeconds ( ) !== 0 ? state . timeLeft : state . duration ,
5661 counting : true ,
62+ notifications : [ ] ,
5763 } )
5864
5965 case STOP_TIMER :
@@ -66,6 +72,11 @@ export const timerReducers = (
6672 timeLeft : state . timeLeft . reduceByOneSecond ( ) ,
6773 } )
6874
75+ case ADD_NOTIFICATION :
76+ return Object . assign ( { } , state , {
77+ notifications : [ action . payload , ...state . notifications ] ,
78+ } )
79+
6980 default :
7081 return state
7182 }
0 commit comments