| 1 |
/** |
| 2 |
* JavaScript code for the "Edit" section integration of Snackbar Notices. |
| 3 |
* |
| 4 |
* @package TablePress |
| 5 |
* @subpackage Views JavaScript |
| 6 |
* @author Tobias Bäthge |
| 7 |
* @since 3.1.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
/** |
| 11 |
* WordPress dependencies. |
| 12 |
*/ |
| 13 |
import { SnackbarList } from '@wordpress/components'; |
| 14 |
import { useDispatch, useSelect } from '@wordpress/data'; |
| 15 |
import { store as noticesStore } from '@wordpress/notices'; |
| 16 |
|
| 17 |
const Notifications = () => { |
| 18 |
const { removeNotice } = useDispatch( noticesStore ); |
| 19 |
const notices = useSelect( |
| 20 |
( select ) => select( noticesStore ).getNotices(), |
| 21 |
[] |
| 22 |
); |
| 23 |
const snackbarNotices = notices.filter( ( { type } ) => type === 'snackbar' ); |
| 24 |
|
| 25 |
if ( snackbarNotices.length === 0 ) { |
| 26 |
return null; |
| 27 |
} |
| 28 |
|
| 29 |
return ( |
| 30 |
<SnackbarList |
| 31 |
notices={ snackbarNotices } |
| 32 |
onRemove={ removeNotice } |
| 33 |
/> |
| 34 |
); |
| 35 |
}; |
| 36 |
|
| 37 |
export { Notifications }; |
| 38 |
|