File size: 958 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
38
39
40
41
42
import { withStorageKey } from '@automattic/state-utils';
import { ADMIN_MENU_RECEIVE, ADMIN_MENU_REQUEST } from 'calypso/state/action-types';
import {
	keyedReducer,
	combineReducers,
	withSchemaValidation,
	withPersistence,
} from 'calypso/state/utils';
import 'calypso/state/data-layer/wpcom/sites/admin-menu';
import { menusSchema } from './schema';

const menusReducer = ( state = [], action ) => {
	switch ( action.type ) {
		case ADMIN_MENU_RECEIVE:
			return action.menu;
		default:
			return state;
	}
};

export const menus = withSchemaValidation(
	menusSchema,
	keyedReducer( 'siteId', withPersistence( menusReducer ) )
);

export const requesting = ( state = false, action ) => {
	switch ( action.type ) {
		case ADMIN_MENU_REQUEST:
		case ADMIN_MENU_RECEIVE:
			return action.type === ADMIN_MENU_REQUEST;
	}

	return state;
};

const reducer = combineReducers( {
	menus,
	requesting,
} );

export default withStorageKey( 'adminMenu', reducer );