Skip to content

Commit

Permalink
Zoom Out: Run the hook in the inserter component so it doesn't keep r…
Browse files Browse the repository at this point in the history
…unning on each mount of the pattern category preview panel
  • Loading branch information
scruffian committed Jul 9, 2024
1 parent ae20515 commit b1ff9bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
* Internal dependencies
*/
import { PatternCategoryPreviews } from './pattern-category-previews';
import { useZoomOut } from '../../../hooks/use-zoom-out';

function PatternCategoryPreviewPanelInner( {
export function PatternCategoryPreviewPanel( {
rootClientId,
onInsert,
onHover,
Expand All @@ -24,17 +23,3 @@ function PatternCategoryPreviewPanelInner( {
/>
);
}

function PatternCategoryPreviewPanelWithZoomOut( props ) {
useZoomOut();
return <PatternCategoryPreviewPanelInner { ...props } />;
}

export function PatternCategoryPreviewPanel( props ) {
// When the pattern panel is showing, we want to use zoom out mode
if ( window.__experimentalEnableZoomedOutPatternsTab ) {
return <PatternCategoryPreviewPanelWithZoomOut { ...props } />;
}

return <PatternCategoryPreviewPanelInner { ...props } />;
}
6 changes: 6 additions & 0 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +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 { useZoomOut } from '../../hooks/use-zoom-out';

const NOOP = () => {};
function InserterMenu(
Expand Down Expand Up @@ -145,6 +146,11 @@ function InserterMenu(

const showMediaPanel = selectedTab === 'media' && !! selectedMediaCategory;

const showZoomOut =
showPatternPanel && window.__experimentalEnableZoomedOutPatternsTab;

useZoomOut( showZoomOut );

const inserterSearch = useMemo( () => {
if ( selectedTab === 'media' ) {
return null;
Expand Down

0 comments on commit b1ff9bd

Please sign in to comment.