From 9870002bebbf900a5d85ab66f08cef713b01d01e Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Mon, 10 May 2021 11:49:58 +0400 Subject: [PATCH] Navigation Editor: "Add new pages" use menu entity --- .../inspector-additions/auto-add-pages.js | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/packages/edit-navigation/src/components/inspector-additions/auto-add-pages.js b/packages/edit-navigation/src/components/inspector-additions/auto-add-pages.js index 9e6d53853534f3..e1ae4d9fbbe6e7 100644 --- a/packages/edit-navigation/src/components/inspector-additions/auto-add-pages.js +++ b/packages/edit-navigation/src/components/inspector-additions/auto-add-pages.js @@ -1,25 +1,19 @@ /** * WordPress dependencies */ -import { useSelect, useDispatch } from '@wordpress/data'; -import { useState, useEffect } from '@wordpress/element'; import { ToggleControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; -export default function AutoAddPages( { menuId } ) { - const menu = useSelect( ( select ) => select( 'core' ).getMenu( menuId ), [ - menuId, - ] ); - - const [ autoAddPages, setAutoAddPages ] = useState( null ); - - useEffect( () => { - if ( autoAddPages === null && menu ) { - setAutoAddPages( menu.auto_add ); - } - }, [ autoAddPages, menu ] ); +/** + * Internal dependencies + */ +import { useMenuEntityProp } from '../../hooks'; - const { saveMenu } = useDispatch( 'core' ); +export default function AutoAddPages( { menuId } ) { + const [ autoAddPages, setAutoAddPages ] = useMenuEntityProp( + 'auto_add', + menuId + ); return ( { - setAutoAddPages( newAutoAddPages ); - saveMenu( { - ...menu, - auto_add: newAutoAddPages, - } ); - } } + onChange={ setAutoAddPages } /> ); }