import { __ } from '@wordpress/i18n'; import { InspectorControls, BlockControls } from "@wordpress/block-editor"; import ServerSideRender from "@wordpress/server-side-render"; import { SelectControl, ToolbarGroup, ToolbarButton, ToggleControl, Panel, PanelBody, PanelRow, } from "@wordpress/components"; import { useBlockProps } from "@wordpress/block-editor"; import { select, subscribe } from '@wordpress/data'; import {useEffect, useState} from 'react'; export default function Edit({ attributes, setAttributes }) { const blockProps = useBlockProps(); /* Update SimpleTOC if the post is saved successfully. */ /* Source: https://github.com/WordPress/gutenberg/issues/17632 */ const { isSavingPost } = select( 'core/editor' ); const [isSavingProcess, setSavingProcess] = useState(false); subscribe(() => { if (isSavingPost()) { setSavingProcess(true); } else { setSavingProcess(false); } }); const updatePost = function () { setAttributes({ updated: Date.now() }); }; useEffect(() => { if (isSavingProcess) { updatePost(); } }, [isSavingProcess]); return (