-
Notifications
You must be signed in to change notification settings - Fork 11
/
Header.ts
40 lines (36 loc) · 1.25 KB
/
Header.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Reducer } from 'redux';
import { produce } from 'immer';
// == state ========================================================================================
export interface State {
isSeeking: boolean;
isSeekbarHovered: boolean;
}
export const initialState: Readonly<State> = {
isSeeking: false,
isSeekbarHovered: false
};
// == action =======================================================================================
export type Action = {
type: 'Header/SeekDown';
} | {
type: 'Header/SeekUp';
} | {
type: 'Header/SeekbarEnter';
} | {
type: 'Header/SeekbarLeave';
};
// == reducer ======================================================================================
export const reducer: Reducer<State, Action> = ( state = initialState, action ) => {
return produce( state, ( newState: State ) => {
if ( action.type === 'Header/SeekDown' ) {
newState.isSeeking = true;
newState.isSeekbarHovered = true; // just in case
} else if ( action.type === 'Header/SeekUp' ) {
newState.isSeeking = false;
} else if ( action.type === 'Header/SeekbarEnter' ) {
newState.isSeekbarHovered = true;
} else if ( action.type === 'Header/SeekbarLeave' ) {
newState.isSeekbarHovered = false;
}
} );
};