Switch sidebar tab when block is selected

[MAILPOET-2451]
This commit is contained in:
Rostislav Wolny
2019-12-02 17:26:10 +01:00
committed by Jack Kitterhing
parent d27581e805
commit f806a24332

View File

@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { IconButton } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
@@ -34,8 +34,21 @@ export default () => {
[]
);
const selectedBlockId = useSelect(
(select) => select('core/block-editor').getSelectedBlockClientId(),
[]
);
const { toggleSidebar, switchSidebarTab } = useDispatch('mailpoet-form-editor');
useEffect(() => {
if (selectedBlockId) {
switchSidebarTab('block');
} else {
switchSidebarTab('form');
}
}, [selectedBlockId, switchSidebarTab]);
return (
<div className="edit-post-sidebar">
<SidebarHeader closeSidebar={() => toggleSidebar(false)}>