-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Site Editor: Initial routing refactoring to separate preview from lis…
…t view (#57938) Co-authored-by: André Maneiro <583546+oandregal@users.noreply.github.com>
- Loading branch information
1 parent
90d7f56
commit 7105a03
Showing
11 changed files
with
363 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* 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 DataviewsPatterns from '../page-patterns/dataviews-patterns'; | ||
import PagePages from '../page-pages'; | ||
import PagePatterns from '../page-patterns'; | ||
import PageTemplateParts from '../page-template-parts'; | ||
import PageTemplates from '../page-templates'; | ||
|
||
const { useLocation } = unlock( routerPrivateApis ); | ||
|
||
export default function useLayoutAreas() { | ||
const isSiteEditorLoading = useIsSiteEditorLoading(); | ||
const { params } = useLocation(); | ||
const { postType, postId, path, layout, isCustom } = params ?? {}; | ||
|
||
// Regular page | ||
if ( path === '/page' ) { | ||
const isListLayout = | ||
isCustom !== 'true' && ( ! layout || layout === 'list' ); | ||
return { | ||
areas: { | ||
content: window.__experimentalAdminViews ? ( | ||
<PagePages /> | ||
) : undefined, | ||
preview: ( isListLayout || | ||
! window.__experimentalAdminViews ) && ( | ||
<Editor isLoading={ isSiteEditorLoading } /> | ||
), | ||
}, | ||
widths: { | ||
content: | ||
window.__experimentalAdminViews && isListLayout | ||
? 380 | ||
: undefined, | ||
}, | ||
}; | ||
} | ||
|
||
// Regular other post types | ||
if ( postType && postId ) { | ||
return { | ||
areas: { | ||
preview: <Editor isLoading={ isSiteEditorLoading } />, | ||
}, | ||
}; | ||
} | ||
|
||
// Templates | ||
if ( | ||
path === '/wp_template/all' || | ||
( path === '/wp_template' && window?.__experimentalAdminViews ) | ||
) { | ||
const isListLayout = | ||
isCustom !== 'true' && ( ! layout || layout === 'list' ); | ||
return { | ||
areas: { | ||
content: <PageTemplates />, | ||
preview: isListLayout && ( | ||
<Editor isLoading={ isSiteEditorLoading } /> | ||
), | ||
}, | ||
widths: { | ||
content: isListLayout ? 380 : undefined, | ||
}, | ||
}; | ||
} | ||
|
||
// Template parts | ||
if ( path === '/wp_template_part/all' ) { | ||
return { | ||
areas: { | ||
content: <PageTemplateParts />, | ||
}, | ||
}; | ||
} | ||
|
||
// Patterns | ||
if ( path === '/patterns' ) { | ||
return { | ||
areas: { | ||
content: window?.__experimentalAdminViews ? ( | ||
<DataviewsPatterns /> | ||
) : ( | ||
<PagePatterns /> | ||
), | ||
}, | ||
}; | ||
} | ||
|
||
// Fallback shows the home page preview | ||
return { | ||
areas: { preview: <Editor isLoading={ isSiteEditorLoading } /> }, | ||
}; | ||
} |
Oops, something went wrong.