Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Register on the site editor only
Browse files Browse the repository at this point in the history
  • Loading branch information
albarin committed Jan 12, 2023
1 parent 0280143 commit 74393de
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions assets/js/blocks/catalog-sorting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,44 @@
import { registerBlockType } from '@wordpress/blocks';
import { Icon } from '@wordpress/icons';
import { totals } from '@woocommerce/icons';
import { select, subscribe } from '@wordpress/data';

/**
* Internal dependencies
*/
import metadata from './block.json';
import edit from './edit';

registerBlockType( metadata, {
icon: {
src: (
<Icon
icon={ totals }
className="wc-block-editor-components-block-icon"
/>
),
},
attributes: {
...metadata.attributes,
},
edit,
save() {
return null;
},
let currentEditorMode: string | undefined;

subscribe( () => {
const store = select( 'core/edit-site' );

const prevEditorMode = currentEditorMode;
currentEditorMode = store?.getEditorMode();

if (
prevEditorMode === currentEditorMode ||
currentEditorMode !== 'visual'
) {
return;
}

registerBlockType( metadata, {
icon: {
src: (
<Icon
icon={ totals }
className="wc-block-editor-components-block-icon"
/>
),
},
attributes: {
...metadata.attributes,
},
edit,
save() {
return null;
},
} );
} );

0 comments on commit 74393de

Please sign in to comment.