Skip to content

Commit

Permalink
Avoid reliance on status constants when consuming useCreateNavigation…
Browse files Browse the repository at this point in the history
…Menu hook (WordPress#42704)

* Export named status vars

* Export vars with correct names
  • Loading branch information
getdave authored Jul 29, 2022
1 parent f61be48 commit e18a82f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 7 additions & 11 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ import useConvertClassicToBlockMenu, {
CLASSIC_MENU_CONVERSION_PENDING,
CLASSIC_MENU_CONVERSION_SUCCESS,
} from './use-convert-classic-menu-to-block-menu';
import useCreateNavigationMenu, {
CREATE_NAVIGATION_MENU_ERROR,
CREATE_NAVIGATION_MENU_PENDING,
CREATE_NAVIGATION_MENU_SUCCESS,
} from './use-create-navigation-menu';
import useCreateNavigationMenu from './use-create-navigation-menu';

const EMPTY_ARRAY = [];

Expand Down Expand Up @@ -157,19 +153,19 @@ function Navigation( {
status: createNavigationMenuStatus,
error: createNavigationMenuError,
value: createNavigationMenuPost,
isPending: isCreatingNavigationMenu,
isSuccess: createNavigationMenuIsSuccess,
isError: createNavigationMenuIsError,
} = useCreateNavigationMenu( clientId );

const isCreatingNavigationMenu =
createNavigationMenuStatus === CREATE_NAVIGATION_MENU_PENDING;

useEffect( () => {
hideNavigationMenuCreateNotice();

if ( createNavigationMenuStatus === CREATE_NAVIGATION_MENU_PENDING ) {
if ( isCreatingNavigationMenu ) {
speak( __( `Creating Navigation Menu.` ) );
}

if ( createNavigationMenuStatus === CREATE_NAVIGATION_MENU_SUCCESS ) {
if ( createNavigationMenuIsSuccess ) {
setRef( createNavigationMenuPost.id );
selectBlock( clientId );

Expand All @@ -178,7 +174,7 @@ function Navigation( {
);
}

if ( createNavigationMenuStatus === CREATE_NAVIGATION_MENU_ERROR ) {
if ( createNavigationMenuIsError ) {
showNavigationMenuCreateNotice(
__( 'Failed to create Navigation Menu.' )
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,9 @@ export default function useCreateNavigationMenu( clientId ) {
status,
value,
error,
isIdle: status === CREATE_NAVIGATION_MENU_IDLE,
isPending: status === CREATE_NAVIGATION_MENU_PENDING,
isSuccess: status === CREATE_NAVIGATION_MENU_SUCCESS,
isError: status === CREATE_NAVIGATION_MENU_ERROR,
};
}

0 comments on commit e18a82f

Please sign in to comment.