1
- import * as React from "react" ;
1
+ import { MouseEvent , useState } from "react" ;
2
2
import {
3
3
AppBar ,
4
+ Avatar ,
4
5
Box ,
5
6
Button ,
6
7
Container ,
7
8
IconButton ,
8
9
Menu ,
9
10
MenuItem ,
10
11
Toolbar ,
12
+ Tooltip ,
11
13
Typography ,
12
14
} from "@mui/material" ;
13
15
import MenuIcon from "@mui/icons-material/Menu" ;
14
16
import AdbIcon from "@mui/icons-material/Adb" ;
17
+ import { useAuth } from "../auth/auth.context" ;
15
18
16
19
const pages = [ "Products" , "Pricing" , "Blog" ] ;
17
20
const authPages = [
@@ -24,20 +27,17 @@ const authPages = [
24
27
link : "/signup" ,
25
28
} ,
26
29
] ;
27
- const settings = [ "Profile" , "Account" , "Dashboard" , "Logout" ] ;
28
30
29
- function Navbar ( ) {
30
- const [ anchorElNav , setAnchorElNav ] = React . useState < null | HTMLElement > (
31
- null
32
- ) ;
33
- const [ anchorElUser , setAnchorElUser ] = React . useState < null | HTMLElement > (
34
- null
35
- ) ;
31
+ export default function Navbar ( ) {
32
+ const { user, logout } = useAuth ( ) ;
33
+ const [ anchorElNav , setAnchorElNav ] = useState < null | HTMLElement > ( null ) ;
34
+ const [ anchorElUser , setAnchorElUser ] = useState < null | HTMLElement > ( null ) ;
36
35
37
- const handleOpenNavMenu = ( event : React . MouseEvent < HTMLElement > ) => {
36
+ const handleOpenNavMenu = ( event : MouseEvent < HTMLElement > ) => {
38
37
setAnchorElNav ( event . currentTarget ) ;
39
38
} ;
40
- const handleOpenUserMenu = ( event : React . MouseEvent < HTMLElement > ) => {
39
+
40
+ const handleOpenUserMenu = ( event : MouseEvent < HTMLElement > ) => {
41
41
setAnchorElUser ( event . currentTarget ) ;
42
42
} ;
43
43
@@ -49,6 +49,13 @@ function Navbar() {
49
49
setAnchorElUser ( null ) ;
50
50
} ;
51
51
52
+ const settings = [
53
+ { name : "Profile" , onclick : handleCloseUserMenu } ,
54
+ { name : "Account" , onclick : handleCloseUserMenu } ,
55
+ { name : "Dashboard" , onclick : handleCloseUserMenu } ,
56
+ { name : "Logout" , onclick : logout } ,
57
+ ] ;
58
+
52
59
return (
53
60
< AppBar position = "static" >
54
61
< Container maxWidth = "xl" >
@@ -62,7 +69,7 @@ function Navbar() {
62
69
sx = { {
63
70
mr : 2 ,
64
71
display : { xs : "none" , md : "flex" } ,
65
- fontFamily : "monospace " ,
72
+ fontFamily : "Roboto " ,
66
73
fontWeight : 700 ,
67
74
letterSpacing : ".3rem" ,
68
75
color : "inherit" ,
@@ -145,18 +152,27 @@ function Navbar() {
145
152
</ Box >
146
153
147
154
< Box sx = { { flexGrow : 0 } } >
148
- < Box sx = { { flexGrow : 1 , display : { xs : "none" , md : "flex" } } } >
149
- { authPages . map ( ( page ) => (
150
- < Button
151
- key = { page . name }
152
- // onClick={handleCloseNavMenu}
153
- href = { page . link }
154
- sx = { { my : 2 , color : "white" , display : "block" } }
155
- >
156
- { page . name }
157
- </ Button >
158
- ) ) }
159
- </ Box >
155
+ { ! user && (
156
+ < Box sx = { { flexGrow : 1 , display : { xs : "none" , md : "flex" } } } >
157
+ { authPages . map ( ( page ) => (
158
+ < Button
159
+ key = { page . name }
160
+ // onClick={handleCloseNavMenu}
161
+ href = { page . link }
162
+ sx = { { my : 2 , color : "white" , display : "block" } }
163
+ >
164
+ { page . name }
165
+ </ Button >
166
+ ) ) }
167
+ </ Box >
168
+ ) }
169
+ { user && (
170
+ < Tooltip title = "Open settings" >
171
+ < IconButton onClick = { handleOpenUserMenu } sx = { { p : 0 } } >
172
+ < Avatar alt = "Remy Sharp" src = "/static/images/avatar/2.jpg" />
173
+ </ IconButton >
174
+ </ Tooltip >
175
+ ) }
160
176
< Menu
161
177
sx = { { mt : "45px" } }
162
178
id = "menu-appbar"
@@ -174,8 +190,8 @@ function Navbar() {
174
190
onClose = { handleCloseUserMenu }
175
191
>
176
192
{ settings . map ( ( setting ) => (
177
- < MenuItem key = { setting } onClick = { handleCloseUserMenu } >
178
- < Typography textAlign = "center" > { setting } </ Typography >
193
+ < MenuItem key = { setting . name } onClick = { setting . onclick } >
194
+ < Typography textAlign = "center" > { setting . name } </ Typography >
179
195
</ MenuItem >
180
196
) ) }
181
197
</ Menu >
@@ -185,4 +201,3 @@ function Navbar() {
185
201
</ AppBar >
186
202
) ;
187
203
}
188
- export default Navbar ;
0 commit comments