Skip to content

Commit

Permalink
First commit. try to navigate to section: /revisions from the revisio…
Browse files Browse the repository at this point in the history
…ns button
  • Loading branch information
ramonjd committed Dec 6, 2024
1 parent 8057435 commit a5017c3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/edit-site/src/components/global-styles/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { moreVertical } from '@wordpress/icons';
import { store as coreStore } from '@wordpress/core-data';
import { useEffect } from '@wordpress/element';
import { usePrevious } from '@wordpress/compose';
import { privateApis as routerPrivateApis } from '@wordpress/router';

/**
* Internal dependencies
Expand Down Expand Up @@ -52,6 +53,7 @@ const SLOT_FILL_NAME = 'GlobalStylesMenu';
const { useGlobalStylesReset } = unlock( blockEditorPrivateApis );
const { Slot: GlobalStylesMenuSlot, Fill: GlobalStylesMenuFill } =
createSlotFill( SLOT_FILL_NAME );
const { useLocation } = unlock( routerPrivateApis );

function GlobalStylesActionMenu() {
const [ canReset, onReset ] = useGlobalStylesReset();
Expand Down Expand Up @@ -329,6 +331,8 @@ function NavigationSync( { path: parentPath, onPathChange, children } ) {

function GlobalStylesUI( { path, onPathChange } ) {
const blocks = getBlockTypes();
const { query } = useLocation();
const { canvas } = query;
const editorCanvasContainerView = useSelect(
( select ) =>
unlock( select( editSiteStore ) ).getEditorCanvasContainerView(),
Expand Down Expand Up @@ -440,7 +444,7 @@ function GlobalStylesUI( { path, onPathChange } ) {

<GlobalStylesActionMenu />
<GlobalStylesBlockLink />
<GlobalStylesEditorCanvasContainerLink />
{ 'edit' === canvas && <GlobalStylesEditorCanvasContainerLink /> }
</Navigator>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { __ } from '@wordpress/i18n';
import { useMemo, useState } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { useViewportMatch } from '@wordpress/compose';
import {
Expand All @@ -19,13 +20,15 @@ import Page from '../page';
import { unlock } from '../../lock-unlock';
import StyleBook from '../style-book';
import { STYLE_BOOK_COLOR_GROUPS } from '../style-book/constants';
import { store as editSiteStore } from '../../store';

const { useLocation, useHistory } = unlock( routerPrivateApis );
const { Menu } = unlock( componentsPrivateApis );

const GlobalStylesPageActions = ( {
isStyleBookOpened,
setIsStyleBookOpened,
setIsStyleBookClosed,
} ) => {
return (
<Menu
Expand Down Expand Up @@ -68,6 +71,9 @@ export default function GlobalStylesUIWrapper() {
const { canvas = 'view' } = query;
const [ isStyleBookOpened, setIsStyleBookOpened ] = useState( false );
const isMobileViewport = useViewportMatch( 'medium', '<' );
const { setEditorCanvasContainerView } = unlock(
useDispatch( editSiteStore )
);
const [ section, onChangeSection ] = useMemo( () => {
return [
query.section ?? '/',
Expand All @@ -80,6 +86,26 @@ export default function GlobalStylesUIWrapper() {
},
];
}, [ path, query.section, history ] );
console.log( { isStyleBookOpened, section, canvas } );

/*
@TODO This needs refactoring. Or at least ScreenRevision needs to be refactored/abstracted
so that it doesn't know about the editorCanvasContainerView.
*/
/* const turnOn = () => {
setEditorCanvasContainerView(
section === '/revisions'
? 'global-styles-revisions:style-book'
: 'style-book'
);
setIsStyleBookOpened( true );
};
const turnOff = () => {
setEditorCanvasContainerView( 'style-book' );
setIsStyleBookOpened( false );
};*/

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ export function SidebarNavigationItemGlobalStyles( props ) {

export default function SidebarNavigationScreenGlobalStyles() {
const history = useHistory();
const { path, query } = useLocation();
const { path } = useLocation();
const {
revisions,
isLoading: isLoadingRevisions,
revisionsCount,
} = useGlobalStylesRevisions();
const openRevisions = useCallback(
async () =>
() =>
history.navigate(
addQueryArgs( path, {
section: '/revisions',
} )
),
[ path, query.section, history ]
[ path, history ]
);

// If there are no revisions, do not render a footer.
Expand Down

0 comments on commit a5017c3

Please sign in to comment.