Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
use hook to handle zoom out view, the hook respects the current zoom …
…out setting
  • Loading branch information
draganescu committed Oct 7, 2024
commit 14ba0f7687f52222861dc66e1c0efcd34916aab4
23 changes: 6 additions & 17 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { VisuallyHidden, SearchControl, Popover } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useDebouncedInput } from '@wordpress/compose';
import { useSelect, useDispatch } from '@wordpress/data';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -32,7 +32,7 @@ import InserterSearchResults from './search-results';
import useInsertionPoint from './hooks/use-insertion-point';
import { store as blockEditorStore } from '../../store';
import TabbedSidebar from '../tabbed-sidebar';
import { unlock } from '../../lock-unlock';
import { useZoomOut } from '../../hooks/use-zoom-out';

const NOOP = () => {};
function InserterMenu(
Expand Down Expand Up @@ -78,6 +78,10 @@ function InserterMenu(
}
const [ selectedTab, setSelectedTab ] = useState( getInitialTab() );

const shouldUseZoomOut =
selectedTab === 'patterns' || selectedTab === 'media';
useZoomOut( shouldUseZoomOut );

const [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ] =
useInsertionPoint( {
rootClientId,
Expand Down Expand Up @@ -284,22 +288,7 @@ function InserterMenu(
showMediaPanel,
] );

const { resetZoomLevel, setZoomLevel, __unstableSetEditorMode } = unlock(
useDispatch( blockEditorStore )
);

const handleZoomOut = ( newSelectedTab ) => {
if ( isZoomOutMode && newSelectedTab === 'blocks' ) {
resetZoomLevel();
__unstableSetEditorMode( 'edit' );
} else if ( ! isZoomOutMode && newSelectedTab === 'patterns' ) {
setZoomLevel( 50 );
__unstableSetEditorMode( 'zoom-out' );
}
};

const handleSetSelectedTab = ( value ) => {
handleZoomOut( value );
// If no longer on patterns tab remove the category setting.
if ( value !== 'patterns' ) {
setSelectedPatternCategory( null );
Expand Down