11import React from 'react' ;
22import PropTypes from 'prop-types' ;
3+ import { connect } from 'react-redux' ;
4+
35import { injectIntl , intlShape } from '@edx/frontend-platform/i18n' ;
46import { getConfig } from '@edx/frontend-platform' ;
7+ import { AvatarButton } from '@openedx/paragon' ;
58
69// Local Components
7- import { AvatarButton } from '@openedx/paragon' ;
810import UserMenuGroupSlot from './plugin-slots/UserMenuGroupSlot' ;
911import UserMenuGroupItemSlot from './plugin-slots/UserMenuGroupItemSlot' ;
1012import { Menu , MenuTrigger , MenuContent } from './Menu' ;
1113import { LinkedLogo , Logo } from './Logo' ;
1214import UserMenuItem from './common/UserMenuItem' ;
13-
15+ import Notifications from './Notifications' ;
16+ import { mapDispatchToProps , mapStateToProps } from './data/selectors' ;
1417// i18n
1518import messages from './Header.messages' ;
1619
@@ -20,6 +23,20 @@ import { MenuIcon } from './Icons';
2023class MobileHeader extends React . Component {
2124 constructor ( props ) { // eslint-disable-line no-useless-constructor
2225 super ( props ) ;
26+ this . state = {
27+ locationHref : window . location . href ,
28+ } ;
29+ }
30+
31+ componentDidMount ( ) {
32+ this . props . fetchAppsNotificationCount ( ) ;
33+ }
34+
35+ componentDidUpdate ( ) {
36+ if ( window . location . href !== this . state . locationHref ) {
37+ this . setState ( { locationHref : window . location . href } ) ;
38+ this . props . fetchAppsNotificationCount ( ) ;
39+ }
2340 }
2441
2542 renderMenu ( menu ) {
@@ -135,6 +152,7 @@ class MobileHeader extends React.Component {
135152 mainMenu,
136153 userMenu,
137154 loggedOutItems,
155+ showNotificationsTray,
138156 } = this . props ;
139157 const logoProps = { src : logo , alt : logoAltText , href : logoDestination } ;
140158 const stickyClassName = stickyOnMobile ? 'sticky-top' : '' ;
@@ -173,6 +191,7 @@ class MobileHeader extends React.Component {
173191 </ div >
174192 { userMenu . length > 0 || loggedOutItems . length > 0 ? (
175193 < div className = "w-100 d-flex justify-content-end align-items-center" >
194+ { showNotificationsTray && loggedIn && < Notifications /> }
176195 < Menu tag = "nav" aria-label = { intl . formatMessage ( messages [ 'header.label.secondary.nav' ] ) } className = "position-static" >
177196 < MenuTrigger
178197 tag = { AvatarButton }
@@ -227,7 +246,8 @@ MobileHeader.propTypes = {
227246 email : PropTypes . string ,
228247 loggedIn : PropTypes . bool ,
229248 stickyOnMobile : PropTypes . bool ,
230-
249+ showNotificationsTray : PropTypes . bool ,
250+ fetchAppsNotificationCount : PropTypes . func . isRequired ,
231251 // i18n
232252 intl : intlShape . isRequired ,
233253} ;
@@ -245,7 +265,7 @@ MobileHeader.defaultProps = {
245265 email : '' ,
246266 loggedIn : false ,
247267 stickyOnMobile : true ,
248-
268+ showNotificationsTray : false ,
249269} ;
250270
251- export default injectIntl ( MobileHeader ) ;
271+ export default connect ( mapStateToProps , mapDispatchToProps ) ( injectIntl ( MobileHeader ) ) ;
0 commit comments