Skip to content

Commit

Permalink
Make reverting to Sync revert to saved pattern blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz committed May 2, 2023
1 parent 6ab1c71 commit e9e9308
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions packages/block-library/src/pattern/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,27 @@ const PatternEdit = ( { attributes, clientId, setAttributes } ) => {
className: forcedAlignment && `align${ forcedAlignment }`,
} );
const innerBlocksProps = useInnerBlocksProps( blockProps, {} );

const handleSync = () => {
if ( syncStatus === 'synced' ) {
setAttributes( { syncStatus: 'unsynced' } );
} else {
setAttributes( { syncStatus: 'synced' } );
replaceInnerBlocks(
clientId,
selectedPattern.blocks.map( ( block ) => cloneBlock( block ) )
);
}
};

return (
<>
<div { ...innerBlocksProps } data-pattern-slug={ slug } />
<BlockControls group="other">
<ToolbarButton
onClick={ () =>
setAttributes( {
syncStatus:
syncStatus === 'unsynced'
? 'synced'
: 'unsynced',
} )
}
>
<ToolbarButton onClick={ handleSync }>
{ syncStatus === 'unsynced'
? __( 'Sync' )
: __( 'Unsync' ) }
: __( 'Desync' ) }
</ToolbarButton>
</BlockControls>
</>
Expand Down

0 comments on commit e9e9308

Please sign in to comment.