Skip to content

Commit

Permalink
Fix issue with all category auto opening when tab first opened
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz committed Sep 12, 2023
1 parent 8839f7a commit 5951dad
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
* WordPress dependencies
*/
import { Modal } from '@wordpress/components';
import { useState, useEffect } from '@wordpress/element';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { usePrevious } from '@wordpress/compose';

/**
* Internal dependencies
Expand All @@ -27,24 +26,6 @@ function PatternsExplorer( { initialCategory, rootClientId } ) {
initialCategory?.name
);

const previousSyncFilter = usePrevious( patternSyncFilter );

// If the sync filter changes, we need to select the "All" category to avoid
// showing a confusing no results screen.
useEffect( () => {
if (
patternSyncFilter !== null &&
previousSyncFilter !== patternSyncFilter
) {
setSelectedCategory( initialCategory?.name );
}
}, [
patternSyncFilter,
previousSyncFilter,
patternSourceFilter,
initialCategory?.name,
] );

const patternCategories = usePatternsCategories(
rootClientId,
patternSourceFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useEffect,
} from '@wordpress/element';
import { _x, __, _n, isRTL, sprintf } from '@wordpress/i18n';
import { useViewportMatch, usePrevious } from '@wordpress/compose';
import { useViewportMatch } from '@wordpress/compose';
import {
__experimentalItemGroup as ItemGroup,
__experimentalItem as Item,
Expand Down Expand Up @@ -315,23 +315,6 @@ function BlockPatternsTabs( {
const settings = getSettings();
return settings.patternsSyncFilter || 'all';
}, [] );
const previousSyncFilter = usePrevious( patternSyncFilter );

// If the sync filter changes, we need to select the "All" category to avoid
// showing a confusing no results screen.
useEffect( () => {
if (
patternSyncFilter !== null &&
previousSyncFilter !== patternSyncFilter
) {
onSelectCategory( allPatternsCategory, patternSourceFilter );
}
}, [
patternSyncFilter,
previousSyncFilter,
onSelectCategory,
patternSourceFilter,
] );

const categories = usePatternsCategories(
rootClientId,
Expand Down

0 comments on commit 5951dad

Please sign in to comment.