-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
82 lines (73 loc) · 1.8 KB
/
index.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* WordPress dependencies
*/
import { useEffect, useRef } from '@wordpress/element';
import {
__experimentalNavigation as Navigation,
__experimentalNavigationMenu as NavigationMenu,
__experimentalNavigationBackButton as NavigationBackButton,
} from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import TemplateSwitcher from './template-switcher';
const NavigationPanel = () => {
const ref = useRef();
useEffect( () => {
ref.current.focus();
}, [ ref ] );
const { templateId, templatePartId, templateType, page } = useSelect(
( select ) => {
const {
getTemplateId,
getTemplatePartId,
getTemplateType,
getPage,
} = select( 'core/edit-site' );
return {
templateId: getTemplateId(),
templatePartId: getTemplatePartId(),
templateType: getTemplateType(),
page: getPage(),
};
},
[]
);
const {
setTemplate,
addTemplate,
removeTemplate,
setTemplatePart,
} = useDispatch( 'core/edit-site' );
return (
<div className="edit-site-navigation-panel">
<Navigation
activeItem={
'wp_template' === templateType
? `template-${ templateId }`
: `template-part-${ templatePartId }`
}
>
<NavigationBackButton
backButtonLabel={ __( 'Dashboard' ) }
className="edit-site-navigation-panel__back-to-dashboard"
href="index.php"
ref={ ref }
/>
<NavigationMenu title="Home">
<TemplateSwitcher
page={ page }
activeId={ templateId }
onActiveIdChange={ setTemplate }
onActiveTemplatePartIdChange={ setTemplatePart }
onAddTemplate={ addTemplate }
onRemoveTemplate={ removeTemplate }
/>
</NavigationMenu>
</Navigation>
</div>
);
};
export default NavigationPanel;