-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
66 lines (60 loc) · 1.65 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
/**
* WordPress dependencies
*/
import { SlotFillProvider } from '@wordpress/components';
import { UnsavedChangesWarning } from '@wordpress/editor';
import { store as noticesStore } from '@wordpress/notices';
import { useDispatch } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';
import { PluginArea } from '@wordpress/plugins';
/**
* Internal dependencies
*/
import { Routes } from '../routes';
import Editor from '../editor';
import List from '../list';
import NavigationSidebar from '../navigation-sidebar';
import getIsListPage from '../../utils/get-is-list-page';
export default function EditSiteApp( { reboot } ) {
const { createErrorNotice } = useDispatch( noticesStore );
function onPluginAreaError( name ) {
createErrorNotice(
sprintf(
/* translators: %s: plugin name */
__(
'The "%s" plugin has encountered an error and cannot be rendered.'
),
name
)
);
}
return (
<SlotFillProvider>
<UnsavedChangesWarning />
<Routes>
{ ( { params } ) => {
const isListPage = getIsListPage( params );
return (
<>
{ isListPage ? (
<List />
) : (
<Editor onError={ reboot } />
) }
<PluginArea onError={ onPluginAreaError } />
{ /* Keep the instance of the sidebar to ensure focus will not be lost
* when navigating to other pages. */ }
<NavigationSidebar
// Open the navigation sidebar by default when in the list page.
isDefaultOpen={ !! isListPage }
activeTemplateType={
isListPage ? params.postType : undefined
}
/>
</>
);
} }
</Routes>
</SlotFillProvider>
);
}