Skip to content

Commit

Permalink
Create isComplementaryAreaLoading selector
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderBart committed Feb 3, 2023
1 parent 0657420 commit 573ddf9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
23 changes: 7 additions & 16 deletions packages/interface/src/components/complementary-area/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { __ } from '@wordpress/i18n';
import { check, starEmpty, starFilled } from '@wordpress/icons';
import { useEffect, useRef } from '@wordpress/element';
import { store as viewportStore } from '@wordpress/viewport';
import { store as preferencesStore } from '@wordpress/preferences';

/**
* Internal dependencies
Expand Down Expand Up @@ -104,17 +103,16 @@ function ComplementaryArea( {
const { isLoading, isActive, isPinned, activeArea, isSmall, isLarge } =
useSelect(
( select ) => {
const { getActiveComplementaryArea, isItemPinned } =
select( interfaceStore );
const {
getActiveComplementaryArea,
isComplementaryAreaLoading,
isItemPinned,
} = select( interfaceStore );

const isVisible = select( preferencesStore ).get(
scope,
'isComplementaryAreaVisible'
);
const _activeArea = getActiveComplementaryArea( scope );

return {
isLoading: isVisible && _activeArea === undefined,
isLoading: isComplementaryAreaLoading( scope ),
isActive: _activeArea === identifier,
isPinned: isItemPinned( scope, identifier ),
activeArea: _activeArea,
Expand Down Expand Up @@ -147,14 +145,7 @@ function ComplementaryArea( {
} else if ( activeArea === undefined && isSmall ) {
disableComplementaryArea( scope, identifier );
}
}, [
activeArea,
isActiveByDefault,
scope,
identifier,
isSmall,
isLoading,
] );
}, [ activeArea, isActiveByDefault, scope, identifier, isSmall ] );

return (
<>
Expand Down
14 changes: 13 additions & 1 deletion packages/interface/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,26 @@ export const getActiveComplementaryArea = createRegistrySelector(
}

// Return `null` to indicate the user hid the complementary area.
if ( ! isComplementaryAreaVisible ) {
if ( isComplementaryAreaVisible === false ) {
return null;
}

return state?.complementaryAreas?.[ scope ];
}
);

export const isComplementaryAreaLoading = createRegistrySelector(
( select ) => ( state, scope ) => {
const isVisible = select( preferencesStore ).get(
scope,
'isComplementaryAreaVisible'
);
const identifier = state?.complementaryAreas?.[ scope ];

return isVisible && identifier === undefined;
}
);

/**
* Returns a boolean indicating if an item is pinned or not.
*
Expand Down

0 comments on commit 573ddf9

Please sign in to comment.