/
router.js
150 lines (137 loc) · 3.17 KB
/
router.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
* WordPress dependencies
*/
import { privateApis as routerPrivateApis } from '@wordpress/router';
/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
import { useIsSiteEditorLoading } from './hooks';
import Editor from '../editor';
import PagePages from '../page-pages';
import PagePatterns from '../page-patterns';
import PageTemplatesTemplateParts from '../page-templates-template-parts';
import {
TEMPLATE_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
} from '../../utils/constants';
const { useLocation } = unlock( routerPrivateApis );
export default function useLayoutAreas() {
const isSiteEditorLoading = useIsSiteEditorLoading();
const { params } = useLocation();
const { postType, postId, path, layout, isCustom, canvas } = params ?? {};
// Note: Since "sidebar" is not yet supported here,
// returning undefined from "mobile" means show the sidebar.
// Regular page
if ( path === '/page' ) {
return {
areas: {
content: undefined,
preview: <Editor isLoading={ isSiteEditorLoading } />,
mobile:
canvas === 'edit' ? (
<Editor isLoading={ isSiteEditorLoading } />
) : undefined,
},
widths: {
content: undefined,
},
};
}
// List layout is still experimental.
// Extracted it here out of the conditionals so it doesn't unintentionally becomes stable.
const isListLayout =
isCustom !== 'true' &&
layout === 'list' &&
window?.__experimentalAdminViews;
if ( path === '/pages' ) {
return {
areas: {
content: <PagePages />,
preview: isListLayout && (
<Editor isLoading={ isSiteEditorLoading } />
),
},
widths: {
content: isListLayout ? 380 : undefined,
},
};
}
// Regular other post types
if ( postType && postId ) {
return {
areas: {
preview: <Editor isLoading={ isSiteEditorLoading } />,
mobile:
canvas === 'edit' ? (
<Editor isLoading={ isSiteEditorLoading } />
) : undefined,
},
};
}
// Templates
if ( path === '/wp_template/all' ) {
return {
areas: {
content: (
<PageTemplatesTemplateParts
postType={ TEMPLATE_POST_TYPE }
/>
),
preview: isListLayout && (
<Editor isLoading={ isSiteEditorLoading } />
),
mobile: (
<PageTemplatesTemplateParts
postType={ TEMPLATE_POST_TYPE }
/>
),
},
widths: {
content: isListLayout ? 380 : undefined,
},
};
}
// Template parts
if ( path === '/wp_template_part/all' ) {
return {
areas: {
content: (
<PageTemplatesTemplateParts
postType={ TEMPLATE_PART_POST_TYPE }
/>
),
preview: isListLayout && (
<Editor isLoading={ isSiteEditorLoading } />
),
mobile: (
<PageTemplatesTemplateParts
postType={ TEMPLATE_PART_POST_TYPE }
/>
),
},
widths: {
content: isListLayout ? 380 : undefined,
},
};
}
// Patterns
if ( path === '/patterns' ) {
return {
areas: {
content: <PagePatterns />,
mobile: <PagePatterns />,
},
};
}
// Fallback shows the home page preview
return {
areas: {
preview: <Editor isLoading={ isSiteEditorLoading } />,
mobile:
canvas === 'edit' ? (
<Editor isLoading={ isSiteEditorLoading } />
) : undefined,
},
};
}