Skip to content

Commit

Permalink
Global styles: improve navigation logic for revisions screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Oct 8, 2024
1 parent 4dc8a02 commit 43f1d32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import { __, sprintf } from '@wordpress/i18n';
import {
useNavigator,
__experimentalConfirmDialog as ConfirmDialog,
Spinner,
} from '@wordpress/components';
Expand Down Expand Up @@ -33,7 +32,6 @@ const { GlobalStylesContext, areGlobalStyleConfigsEqual } = unlock(
const PAGE_SIZE = 10;

function ScreenRevisions() {
const { goTo } = useNavigator();
const { user: currentEditorGlobalStyles, setUserConfig } =
useContext( GlobalStylesContext );
const { blocks, editorCanvasContainerView } = useSelect(
Expand Down Expand Up @@ -71,6 +69,8 @@ function ScreenRevisions() {
currentEditorGlobalStyles
);

// The actual code that triggers the revisions screen to navigate back
// to the home screen in in `packages/edit-site/src/components/global-styles/ui.js`.
const onCloseRevisions = () => {
const canvasContainerView =
editorCanvasContainerView === 'global-styles-revisions:style-book'
Expand All @@ -85,15 +85,6 @@ function ScreenRevisions() {
onCloseRevisions();
};

useEffect( () => {
if (
! editorCanvasContainerView ||
! editorCanvasContainerView.startsWith( 'global-styles-revisions' )
) {
goTo( '/' ); // Return to global styles main panel.
}
}, [ editorCanvasContainerView ] );

useEffect( () => {
if ( ! isLoading && revisions.length ) {
setCurrentRevisions( revisions );
Expand Down
13 changes: 11 additions & 2 deletions packages/edit-site/src/components/global-styles/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ function GlobalStylesEditorCanvasContainerLink() {
switch ( editorCanvasContainerView ) {
case 'global-styles-revisions':
case 'global-styles-revisions:style-book':
goTo( '/revisions' );
if ( ! isRevisionsOpen ) {
goTo( '/revisions' );
}
break;
case 'global-styles-css':
goTo( '/css' );
Expand All @@ -267,7 +269,14 @@ function GlobalStylesEditorCanvasContainerLink() {
* browsing global styles panel.
*/
if ( isRevisionsOpen ) {
goTo( '/' );
goTo( '/', { isBack: true } );
}
break;
default:
// In general, if the revision screen is in view but the
// `editorCanvasContainerView` is not a revision view, close it.
if ( isRevisionsOpen ) {
goTo( '/', { isBack: true } );
}
break;
}
Expand Down

0 comments on commit 43f1d32

Please sign in to comment.