Skip to content

Commit

Permalink
Add a snackbar when the installation succeeds
Browse files Browse the repository at this point in the history
  • Loading branch information
ryelle committed Jan 21, 2021
1 parent dbb67fa commit 5bde787
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
15 changes: 14 additions & 1 deletion packages/block-directory/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { store as blocksStore } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { controls } from '@wordpress/data';
import { apiFetch } from '@wordpress/data-controls';
import { store as noticesStore } from '@wordpress/notices';
Expand Down Expand Up @@ -96,6 +96,19 @@ export function* installBlockType( block ) {
);
}

yield controls.dispatch(
noticesStore,
'createInfoNotice',
sprintf(
// translators: %s is the block title.
__( 'Block %s installed and added.' ),
block.title
),
{
speak: true,
type: 'snackbar',
}
);
success = true;
} catch ( error ) {
let message = error.message || __( 'An error occurred.' );
Expand Down
16 changes: 14 additions & 2 deletions packages/block-directory/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ describe( 'actions', () => {
type: '@@data/SELECT',
} );

expect( generator.next( [ block ] ).value ).toEqual( {
expect( generator.next( [ block ] ).value ).toMatchObject( {
type: '@@data/DISPATCH',
actionName: 'createInfoNotice',
storeKey: noticesStore,
} );

expect( generator.next().value ).toEqual( {
type: 'SET_INSTALLING_BLOCK',
blockId: block.id,
isInstalling: false,
Expand Down Expand Up @@ -152,7 +158,13 @@ describe( 'actions', () => {
type: '@@data/SELECT',
} );

expect( generator.next( [ inactiveBlock ] ).value ).toEqual( {
expect( generator.next( [ inactiveBlock ] ).value ).toMatchObject( {
type: '@@data/DISPATCH',
actionName: 'createInfoNotice',
storeKey: noticesStore,
} );

expect( generator.next().value ).toEqual( {
type: 'SET_INSTALLING_BLOCK',
blockId: inactiveBlock.id,
isInstalling: false,
Expand Down

0 comments on commit 5bde787

Please sign in to comment.