@@ -2,8 +2,7 @@ import React, {useEffect} from "react";
2
2
3
3
import SearchIcon from '@material-ui/icons/Search' ;
4
4
import AccountCircle from '@material-ui/icons/AccountCircle' ;
5
- import MenuItem from '@material-ui/core/MenuItem' ;
6
- import { Menu , Grid } from '@material-ui/core' ;
5
+ import { Grid } from '@material-ui/core' ;
7
6
import MenuIcon from '@material-ui/icons/Menu' ;
8
7
import MoreIcon from '@material-ui/icons/MoreVert' ;
9
8
import Cookies from 'js-cookie' ;
@@ -35,23 +34,25 @@ import {TABS_DATA_API} from "../../../constants/api_routes";
35
34
import { TABS_API_OBJECT_LEN } from "../../../constants/constants"
36
35
import Avatar from '@material-ui/core/Avatar' ;
37
36
import history from "../../../history" ;
37
+ import MobileMenu from "./mobileMenu" ;
38
38
39
39
const NavBar = props => {
40
40
const classes = useNavBarStyles ( ) ;
41
41
42
42
const [ mobileSearchState , setMobileSearchState ] = React . useState ( false ) ;
43
- const [ mobileMoreAnchorEl , setMobileMoreAnchorEl ] = React . useState ( null ) ;
44
43
const [ hamburgerBtnState , setHamburgerBtnState ] = React . useState ( false ) ;
45
44
46
45
const { isSignedIn, tokenId, firstName} = useSelector ( state => state . signInReducer )
47
46
const googleAuthReducer = useSelector ( state => state . googleAuthReducer )
48
47
const tabsAPIData = useSelector ( state => state . tabsDataReducer )
49
48
50
- const isMobileMenuOpen = Boolean ( mobileMoreAnchorEl ) ;
51
49
const dispatch = useDispatch ( )
52
50
53
51
let authIcon = null
54
52
let authLabel = null
53
+ const mobileMenuId = 'primary-search-account-menu-mobile' ;
54
+ const [ mobileMoreAnchorEl , setMobileMoreAnchorEl ] = React . useState ( null ) ;
55
+ const isMobileMenuOpen = Boolean ( mobileMoreAnchorEl ) ;
55
56
56
57
/**
57
58
* set the cart from saved Cookie
@@ -97,7 +98,7 @@ const NavBar = props => {
97
98
oAuth : auth
98
99
}
99
100
} )
100
- } ) . catch ( function ( e ) {
101
+ } ) . catch ( function ( ) {
101
102
log . error ( `[Navbar] Failed to load google OAuth` )
102
103
} )
103
104
} ) ;
@@ -173,14 +174,6 @@ const NavBar = props => {
173
174
authLabel = "Sign In"
174
175
}
175
176
176
- const handleMobileMenuClose = ( ) => {
177
- setMobileMoreAnchorEl ( null ) ;
178
- } ;
179
-
180
- const handleMobileMenuOpen = ( event ) => {
181
- setMobileMoreAnchorEl ( event . currentTarget ) ;
182
- } ;
183
-
184
177
const changeAuthStatusHandler = ( ) => {
185
178
log . info ( `[Navbar] handleSignOutClick isSignedIn = ${ googleAuthReducer . isSignedInUsingOAuth } ` )
186
179
if ( googleAuthReducer . isSignedInUsingOAuth ) {
@@ -190,7 +183,6 @@ const NavBar = props => {
190
183
} else {
191
184
history . push ( "/signin" )
192
185
}
193
-
194
186
handleMobileMenuClose ( ) ;
195
187
}
196
188
@@ -199,66 +191,34 @@ const NavBar = props => {
199
191
setMobileMoreAnchorEl ( null ) ;
200
192
}
201
193
202
- const mobileMenuId = 'primary-search-account-menu-mobile' ;
203
- const renderMobileMenu = (
204
- < Menu
205
- anchorEl = { mobileMoreAnchorEl }
206
- anchorOrigin = { { vertical : 'top' , horizontal : 'right' } }
207
- id = { mobileMenuId }
208
- keepMounted
209
- transformOrigin = { { vertical : 'top' , horizontal : 'right' } }
210
- open = { isMobileMenuOpen }
211
- onClose = { handleMobileMenuClose } >
212
- < MenuItem onClick = { changeAuthStatusHandler } style = { { padding : "0 0.7rem 0 0" } } >
213
- < Grid container alignItems = "center" >
214
- < Grid item >
215
- < IconButton aria-label = "account of current user"
216
- aria-controls = "primary-search-account-menu"
217
- aria-haspopup = "true"
218
- color = "inherit" >
219
- { authIcon }
220
- </ IconButton >
221
- </ Grid >
222
- < Grid item >
223
- < p > { authLabel } </ p >
224
- </ Grid >
225
- </ Grid >
226
- </ MenuItem >
227
- < MenuItem onClick = { changePageToShoppingBagHandler } style = { { padding : "0 0.7rem 0 0" } } >
228
- < Grid container alignItems = "center" >
229
- < Grid item xs = { 7 } >
230
- < IconButton color = "inherit" >
231
- < BagButton />
232
- </ IconButton >
233
- </ Grid >
234
- < Grid item >
235
- < p > Bag</ p >
236
- </ Grid >
237
- </ Grid >
238
- </ MenuItem >
239
- </ Menu >
240
- ) ;
194
+ const handleMobileMenuClose = ( ) => {
195
+ setMobileMoreAnchorEl ( null ) ;
196
+ } ;
197
+
198
+ const handleMobileMenuOpen = ( event ) => {
199
+ setMobileMoreAnchorEl ( event . currentTarget ) ;
200
+ } ;
241
201
242
202
const handleMobileSearchClose = ( ) => {
243
203
setMobileSearchState ( false )
244
204
}
245
205
206
+ const handleMobileSearchOpen = ( ) => {
207
+ setMobileSearchState ( true )
208
+ }
209
+
246
210
const renderMobileSearchInputField = ( ) => {
247
211
if ( mobileSearchState ) {
248
212
return < SearchBar size = "medium" handleClose = { handleMobileSearchClose } />
249
213
}
250
214
}
251
215
252
- const handleMobileSearchOpen = ( ) => {
253
- setMobileSearchState ( true )
254
- }
255
-
256
- const handleHamburgerBtnClick = ( ) => {
216
+ const handleSidebarOpen = ( ) => {
257
217
log . info ( `[NavBar] opening sidebar` )
258
218
setHamburgerBtnState ( true )
259
219
}
260
220
261
- const sidebarCloseHandler = ( ) => {
221
+ const handleSidebarClose = ( ) => {
262
222
log . info ( `[NavBar] clickAwayListener is triggered` )
263
223
setHamburgerBtnState ( false )
264
224
}
@@ -282,7 +242,7 @@ const NavBar = props => {
282
242
log . info ( `[NavBar]: Rendering NavBar Component` )
283
243
return (
284
244
< >
285
- < SideBar open = { hamburgerBtnState } closeHandler = { sidebarCloseHandler } />
245
+ < SideBar open = { hamburgerBtnState } closeHandler = { handleSidebarClose } />
286
246
287
247
< div style = { { paddingBottom : 80 } } >
288
248
< AppBar color = "default" className = { classes . appBarRoot } >
@@ -295,7 +255,7 @@ const NavBar = props => {
295
255
className = { classes . menuButton }
296
256
color = "inherit"
297
257
aria-label = "open drawer"
298
- onClick = { handleHamburgerBtnClick } >
258
+ onClick = { handleSidebarOpen } >
299
259
< MenuIcon fontSize = "large" />
300
260
</ IconButton >
301
261
</ Grid >
@@ -335,9 +295,9 @@ const NavBar = props => {
335
295
{ renderMobileSearchInputField ( ) }
336
296
</ Hidden >
337
297
338
- < div className = { classes . growHalf } />
339
-
340
298
< Hidden xsDown >
299
+ < div className = { classes . growHalf } />
300
+
341
301
{ renderIndependentElem ( changeAuthStatusHandler , authIcon , authLabel ,
342
302
2 ) }
343
303
@@ -348,22 +308,32 @@ const NavBar = props => {
348
308
</ Hidden >
349
309
350
310
351
- < div className = { classes . sectionMobile } >
352
- < IconButton
353
- aria-label = "show more"
354
- aria-controls = { mobileMenuId }
355
- aria-haspopup = "true"
356
- onClick = { handleMobileMenuOpen }
357
- color = "inherit"
358
- edge = "end" >
359
- < MoreIcon fontSize = "large" />
360
- </ IconButton >
361
- </ div >
311
+ < Hidden smUp >
312
+ < Grid item >
313
+ < IconButton
314
+ aria-label = "show more"
315
+ aria-controls = { mobileMenuId }
316
+ aria-haspopup = "true"
317
+ onClick = { handleMobileMenuOpen }
318
+ color = "inherit"
319
+ edge = "end" >
320
+ < MoreIcon fontSize = "large" />
321
+ </ IconButton >
322
+ </ Grid >
323
+ </ Hidden >
362
324
</ Grid >
363
325
</ Toolbar >
364
326
</ AppBar >
365
327
366
- { renderMobileMenu }
328
+ < MobileMenu mobileMenuId = { mobileMenuId }
329
+ authIcon = { authIcon }
330
+ authLabel = { authLabel }
331
+ authBtnHandler = { changeAuthStatusHandler }
332
+ bagBtnHandler = { changePageToShoppingBagHandler }
333
+ mobileMoreAnchorEl = { mobileMoreAnchorEl }
334
+ isMobileMenuOpen = { isMobileMenuOpen }
335
+ handleMobileMenuClose = { handleMobileMenuClose }
336
+ />
367
337
</ div >
368
338
</ >
369
339
) ;
0 commit comments