images
1 year ago
notification
9 months ago
query
1 year ago
state
1 year ago
index.js
1 year ago
index.scss
1 year ago
notification-icon.jsx
1 year ago
notifications-container.jsx
1 year ago
notifications.jsx
1 year ago
notifications.jsx
31 lines
| 1 | import { NotificationIcon } from './notification-icon'; |
| 2 | import { NotificationsContainer } from './notifications-container'; |
| 3 | import { useWpchillState } from './state/use-wpchill-state'; |
| 4 | import { useNotificationQuery } from './query/useNotificationQuery'; |
| 5 | import { useEffect } from '@wordpress/element'; |
| 6 | import { setVisibleNotifications } from './state/actions'; |
| 7 | |
| 8 | export function Notifications() { |
| 9 | const { data, isLoading } = useNotificationQuery(); |
| 10 | const { state, dispatch } = useWpchillState(); |
| 11 | const { closedBubble, showContainer } = state; |
| 12 | |
| 13 | useEffect( () => { |
| 14 | if ( ! isLoading && data ) { |
| 15 | const allNotifications = Object.values( data ).flat(); |
| 16 | dispatch( setVisibleNotifications( allNotifications ) ); |
| 17 | } |
| 18 | }, [ data, isLoading, dispatch ] ); |
| 19 | |
| 20 | if ( 0 === state.visibleNotifications.length || closedBubble ) { |
| 21 | return null; |
| 22 | } |
| 23 | |
| 24 | return ( |
| 25 | <> |
| 26 | <NotificationIcon /> |
| 27 | { showContainer && <NotificationsContainer /> } |
| 28 | </> |
| 29 | ); |
| 30 | } |
| 31 |