File size: 1,055 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import {
	LAYOUT_FOCUS_SET,
	LAYOUT_NEXT_FOCUS_ACTIVATE,
	LAYOUT_NEXT_FOCUS_SET,
} from 'calypso/state/action-types';

const initialState = { current: 'content', next: null };

export default function layoutFocus( state = initialState, action ) {
	switch ( action.type ) {
		case LAYOUT_FOCUS_SET:
			if ( action.area === state.current ) {
				return state;
			}
			return Object.assign( {}, state, { current: action.area } );
		case LAYOUT_NEXT_FOCUS_SET:
			if ( action.area === state.next ) {
				return state;
			}
			return Object.assign( {}, state, { next: action.area } );
		case LAYOUT_NEXT_FOCUS_ACTIVATE: {
			// If we don't have a change queued, set it to `content`. This avoids
			// having to set the focus to content on all navigation links because it
			// becomes the default after focus has shifted.
			let next = state.next;
			if ( ! next && state.current !== 'content' ) {
				next = 'content';
			}
			if ( ! next ) {
				return state;
			}
			return Object.assign( {}, state, { current: next, next: null } );
		}
	}
	return state;
}