AlkantarClanX12

Your IP : 3.141.38.5


Current Path : /home/thanudqk/thepball.com/wp-content/plugins/hummingbird-performance/_src/js/
Upload File :
Current File : /home/thanudqk/thepball.com/wp-content/plugins/hummingbird-performance/_src/js/block.js

import Fetcher from './utils/fetcher';
import { getString } from './utils/helpers';

const { PluginPostStatusInfo } = wp.editPost;
const { registerPlugin } = wp.plugins;
const { select, dispatch } = wp.data;

/**
 * Handle clear cache action.
 */
const handleClearCache = () => {
	const postId = select( 'core/editor' ).getCurrentPostId();
	Fetcher.caching.clearCacheForPost( postId ).then( showNotice );
};

/**
 * Show notice.
 */
const showNotice = () => {
	const notices = select( 'core/notices' ).getNotices();
	if ( ! notices.find( ( notice ) => notice.id === 'wphb-gb-notice' ) ) {
		const text = getString( 'notice' );
		dispatch( 'core/notices' ).createNotice( 'success', text, {
			id: 'wphb-gb-notice',
		} );
	}
};

/**
 * Add clear cache button.
 *
 * @return {*} Element
 * @class
 */
const MyPluginPostStatusInfo = () => (
	<PluginPostStatusInfo className="wphb-clear-cache">
		<input
			type="submit"
			value={ getString( 'button' ) }
			onClick={ handleClearCache }
			className="components-button is-button is-default is-secondary is-large editor-post-trash"
		/>
	</PluginPostStatusInfo>
);

registerPlugin( 'wphb', { render: MyPluginPostStatusInfo } );