diff --git a/src/common/NavBar/NotificationsMenu/useNotifications.js b/src/common/NavBar/NotificationsMenu/useNotifications.js new file mode 100644 index 000000000..ed14b3d40 --- /dev/null +++ b/src/common/NavBar/NotificationsMenu/useNotifications.js @@ -0,0 +1,27 @@ +const React = require('react'); +const { useServices } = require('stremio/services'); + +const useNotifications = () => { + const [notifications, setNotifications] = React.useState([]); + const { core } = useServices(); + React.useEffect(() => { + const onNewState = () => { + const state = core.getState(); + setNotifications(state.notifications.groups); + }; + core.on('NewModel', onNewState); + core.dispatch({ + action: 'Load', + args: { + load: 'Notifications', + args: { extra: [] } + } + }); + return () => { + core.off('NewModel', onNewState); + }; + }, []); + return notifications; +}; + +module.exports = useNotifications;