Skip to content

Commit

Permalink
Fixes from Enrico
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Apr 5, 2023
1 parent 05cae15 commit 355b4f3
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 249 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/**
* WordPress dependencies
*/
import { BlockSettingsMenuControls } from '@wordpress/block-editor';
import {
BlockSettingsMenuControls,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { serialize } from '@wordpress/blocks';
import { useCallback, useState } from '@wordpress/element';
import {
MenuItem,
Expand All @@ -16,11 +20,6 @@ import { useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';

/**
* Internal dependencies
*/
import { store } from '../../store';

/**
* Menu control to convert block(s) to patterns.
*
Expand All @@ -32,8 +31,23 @@ export default function PatternConvertButton( { clientIds } ) {
const [ isModalOpen, setIsModalOpen ] = useState( false );
const [ title, setTitle ] = useState( '' );

const { __experimentalConvertBlocksToPattern: convertBlocksToPattern } =
useDispatch( store );
const convertBlocksToPattern =
( clientIDs, _title ) =>
async ( { registry } ) => {
const pattern = {
title: _title || __( 'Untitled Pattern' ),
content: serialize(
registry
.select( blockEditorStore )
.getBlocksByClientId( clientIDs )
),
status: 'publish',
};

await registry
.dispatch( 'core' )
.saveEntityRecord( 'postType', 'wp_block_pattern', pattern );
};

const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );
Expand Down
1 change: 0 additions & 1 deletion packages/patterns/src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { store } from './store';
export * from './components';
30 changes: 0 additions & 30 deletions packages/patterns/src/store/actions.js

This file was deleted.

22 changes: 0 additions & 22 deletions packages/patterns/src/store/index.js

This file was deleted.

14 changes: 0 additions & 14 deletions packages/patterns/src/store/test/__snapshots__/actions.js.snap

This file was deleted.

147 changes: 0 additions & 147 deletions packages/patterns/src/store/test/actions.js

This file was deleted.

27 changes: 0 additions & 27 deletions packages/patterns/src/store/test/selectors.js

This file was deleted.

0 comments on commit 355b4f3

Please sign in to comment.