diff --git a/packages/edit-site/src/components/block-editor/index.js b/packages/edit-site/src/components/block-editor/index.js index 512d68fcbe0cf..c3191427bf422 100644 --- a/packages/edit-site/src/components/block-editor/index.js +++ b/packages/edit-site/src/components/block-editor/index.js @@ -178,7 +178,8 @@ export default function BlockEditor() { ) : ( { + const { userRevisions, isDirty, editorRole } = useSelect( ( select ) => { const { __experimentalGetDirtyEntityRecords, isSavingEntityRecord } = select( coreStore ); const dirtyEntityRecords = __experimentalGetDirtyEntityRecords(); @@ -186,6 +188,7 @@ function ScreenRevisions( { onClose } ) { select( coreStore ).__experimentalGetCurrentThemeGlobalStylesRevisions() || [], + editorRole: unlock( select( editSiteStore ) ).getEditorRole(), }; }, [] ); const [ globalStylesRevision, setGlobalStylesRevision ] = useState( {} ); @@ -203,6 +206,14 @@ function ScreenRevisions( { onClose } ) { } setCurrentRevisionId( currentRevision?.id ); }, [ userRevisions, userConfig ] ); + const { setEditorRole } = unlock( useDispatch( editSiteStore ) ); + console.log( 'editorRole', editorRole ); + useEffect( () => { + if ( editorRole !== 'global-styles-revisions' ) { + goBack(); + setEditorRole( editorRole ); + } + }, [ editorRole ] ); const restoreRevision = useCallback( ( revision ) => { @@ -217,6 +228,7 @@ function ScreenRevisions( { onClose } ) { const onCloseRevisions = () => { goBack(); + onClose(); }; const selectRevision = ( revision ) => { diff --git a/packages/edit-site/src/components/global-styles/ui.js b/packages/edit-site/src/components/global-styles/ui.js index d08d3b0286ce4..b5a5e9a287340 100644 --- a/packages/edit-site/src/components/global-styles/ui.js +++ b/packages/edit-site/src/components/global-styles/ui.js @@ -43,6 +43,7 @@ import ScreenCSS from './screen-css'; import { unlock } from '../../private-apis'; import ScreenEffects from './screen-effects'; import ScreenRevisions from './screen-revisions'; +import { store as editSiteStore } from '../../store'; const SLOT_FILL_NAME = 'GlobalStylesMenu'; const { Slot: GlobalStylesMenuSlot, Fill: GlobalStylesMenuFill } = @@ -66,11 +67,16 @@ function GlobalStylesActionMenu() { 0 ) + 1, }; }, [] ); + + const { setEditorRole } = unlock( useDispatch( editSiteStore ) ); const { useGlobalStylesReset } = unlock( blockEditorPrivateApis ); const [ canReset, onReset ] = useGlobalStylesReset(); const { goTo } = useNavigator(); const loadCustomCSS = () => goTo( '/css' ); - const loadRevisions = () => goTo( '/revisions' ); + const loadRevisions = () => { + goTo( '/revisions' ); + setEditorRole( 'global-styles-revisions' ); + }; const hasRevisions = revisionsCount >= 2; return ( @@ -140,6 +146,7 @@ function BlockStyleVariationsScreens( { name } ) { }, [ name ] ); + if ( ! blockStyleVariations?.length ) { return null; } @@ -186,7 +193,7 @@ function ContextScreens( { }, [ name ] ); - + const { setEditorRole } = unlock( useDispatch( editSiteStore ) ); return ( <> @@ -254,7 +261,10 @@ function ContextScreens( { - + setEditorRole( 'init' ) } + /> { !! blockStyleVariations?.length && ( @@ -330,6 +340,11 @@ function GlobalStylesUI( { onCloseStyleBook, } ) { const blocks = getBlockTypes(); + const { editorRole } = useSelect( ( select ) => { + return { + editorRole: unlock( select( editSiteStore ) ).getEditorRole(), + }; + }, [] ); return ( ); } ) } - { isStyleBookOpened && ( + + { 'style-book' === editorRole && ( ) } diff --git a/packages/edit-site/src/components/header-edit-mode/index.js b/packages/edit-site/src/components/header-edit-mode/index.js index 0f085cf9e81e9..27c5c3e0bcbba 100644 --- a/packages/edit-site/src/components/header-edit-mode/index.js +++ b/packages/edit-site/src/components/header-edit-mode/index.js @@ -38,7 +38,7 @@ import UndoButton from './undo-redo/undo'; import RedoButton from './undo-redo/redo'; import DocumentActions from './document-actions'; import { store as editSiteStore } from '../../store'; -import { useHasEditorCanvasFill } from '../editor-canvas'; +import { unlock } from '../../private-apis'; const preventDefault = ( event ) => { event.preventDefault(); @@ -56,6 +56,7 @@ export default function HeaderEditMode() { blockEditorMode, homeUrl, showIconLabels, + editorRole, } = useSelect( ( select ) => { const { __experimentalGetPreviewDeviceType, @@ -88,6 +89,7 @@ export default function HeaderEditMode() { 'core/edit-site', 'showIconLabels' ), + editorRole: unlock( select( editSiteStore ) ).getEditorRole(), }; }, [] ); @@ -117,8 +119,14 @@ export default function HeaderEditMode() { [ setIsListViewOpened, isListViewOpen ] ); - // @TODO We should genericize the style book slot. - const hasEditorCanvasFill = useHasEditorCanvasFill(); + + const defaultRole = 'init' === editorRole; + + // @TODO Abstract this. + const headerTitle = + 'style-book' === editorRole + ? __( 'Style Book' ) + : __( 'Global styles revisions' ); const isFocusMode = templateType === 'wp_template_part'; @@ -139,7 +147,7 @@ export default function HeaderEditMode() { 'show-icon-labels': showIconLabels, } ) } > - { ! hasEditorCanvasFill && ( + { defaultRole && ( - { hasEditorCanvasFill ? ( - __( 'Style Book' ) - ) : ( - - ) } + { ! defaultRole ? headerTitle : }
- { ! isFocusMode && ! hasEditorCanvasFill && ( + { ! isFocusMode && defaultRole && (
select( editSiteStore ).getEditorMode(), - [] - ); - + const { editorMode, editorRole } = useSelect( ( select ) => { + return { + editorMode: select( editSiteStore ).getEditorMode(), + editorRole: unlock( select( editSiteStore ) ).getEditorRole(), + }; + }, [] ); + const { setEditorRole } = unlock( useDispatch( editSiteStore ) ); useEffect( () => { if ( editorMode !== 'visual' ) { - setIsStyleBookOpened( false ); + setEditorRole( 'init' ); } }, [ editorMode ] ); return ( @@ -45,10 +46,14 @@ export default function GlobalStylesSidebar() {