-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bootstrap the dashboard layout #62409
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
UnsavedChangesWarning, | ||
privateApis as editorPrivateApis, | ||
} from '@wordpress/editor'; | ||
import { privateApis as routerPrivateApis } from '@wordpress/router'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Layout from '../layout'; | ||
import Page from '../page'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { RouterProvider } = unlock( routerPrivateApis ); | ||
const { GlobalStylesProvider } = unlock( editorPrivateApis ); | ||
|
||
const defaultRoute = { | ||
key: 'index', | ||
areas: { | ||
sidebar: 'Empty Sidebar', | ||
content: <Page>Welcome to Posts</Page>, | ||
preview: undefined, | ||
mobile: <Page>Welcome to Posts</Page>, | ||
}, | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jsnajdr I wish we can declare the routes of the site editor in a static way like this with an extra "path" or something. For now, having a useLayoutArea hook for the site editor and another one for this new experimental page... works. But there's something to be done here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need to have a hook similar to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
|
||
export default function PostsApp() { | ||
return ( | ||
<GlobalStylesProvider> | ||
<UnsavedChangesWarning /> | ||
<RouterProvider> | ||
<Layout route={ defaultRoute } /> | ||
</RouterProvider> | ||
</GlobalStylesProvider> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { privateApis as commandsPrivateApis } from '@wordpress/commands'; | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editSiteStore } from '../../store'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { useCommandContext } = unlock( commandsPrivateApis ); | ||
|
||
/** | ||
* React hook used to set the correct command context based on the current state. | ||
*/ | ||
export default function useSetCommandContext() { | ||
const { hasBlockSelected, canvasMode } = useSelect( ( select ) => { | ||
const { getCanvasMode } = unlock( select( editSiteStore ) ); | ||
const { getBlockSelectionStart } = select( blockEditorStore ); | ||
return { | ||
canvasMode: getCanvasMode(), | ||
hasBlockSelected: getBlockSelectionStart(), | ||
}; | ||
}, [] ); | ||
// Sets the right context for the command palette | ||
let commandContext = 'site-editor'; | ||
if ( canvasMode === 'edit' ) { | ||
commandContext = 'entity-edit'; | ||
} | ||
if ( hasBlockSelected ) { | ||
commandContext = 'block-selection-edit'; | ||
} | ||
useCommandContext( commandContext ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I basically extracted the site editor specific code from the "Layout" component using this wrapper. Now the
Layout
component is agnostic from the site editor content.