@@ -18,6 +18,7 @@ import { useNavigate, useLocation } from "react-router-dom";
18
18
import { useAuth } from "../../contexts/AuthContext" ;
19
19
import { useState } from "react" ;
20
20
import { USE_AUTH_ERROR_MESSAGE } from "../../utils/constants" ;
21
+ import { isMatchingPage } from "../../utils/url" ;
21
22
22
23
type NavbarItem = { label : string ; link : string ; needsLogin : boolean } ;
23
24
@@ -62,63 +63,76 @@ const Navbar: React.FC<NavbarProps> = (props) => {
62
63
} }
63
64
>
64
65
< AppMargin >
65
- < Toolbar sx = { { padding : 0 } } >
66
+ < Toolbar sx = { { padding : 0 , justifyContent : "space-between" } } >
66
67
< Typography
67
68
component = { Box }
68
69
variant = "h5"
69
- sx = { [ { flexGrow : 1 , "&:hover" : { cursor : "pointer" } } ] }
70
+ sx = { { "&:hover" : { cursor : "pointer" } } }
70
71
onClick = { ( ) => navigate ( "/" ) }
71
72
>
72
73
PeerPrep
73
74
</ Typography >
74
- < Stack direction = { "row" } alignItems = { "center" } spacing = { 2 } >
75
- { navbarItems
76
- . filter ( ( item ) => ! item . needsLogin || ( item . needsLogin && user ) )
77
- . map ( ( item ) => (
78
- < Link
79
- key = { item . label }
80
- href = { item . link }
81
- underline = "none"
82
- sx = { { color : "common.black" } }
83
- >
84
- { path == item . link ? < b > { item . label } </ b > : item . label }
85
- </ Link >
86
- ) ) }
87
- { user ? (
88
- < >
89
- < Tooltip title = { "Account settings" } >
90
- < IconButton onClick = { handleClick } data-testid = "profile" >
91
- < Avatar src = { user . profilePictureUrl } />
92
- </ IconButton >
93
- </ Tooltip >
94
- < Menu
95
- anchorEl = { anchorEl }
96
- open = { ! ! anchorEl }
97
- onClose = { handleClose }
98
- onClick = { handleClose }
99
- >
100
- < MenuItem
101
- onClick = { ( ) => {
102
- handleClose ( ) ;
103
- navigate ( `/profile/${ user . id } ` ) ;
104
- } }
75
+ { ! isMatchingPage ( path ) ? (
76
+ < Stack direction = { "row" } alignItems = { "center" } spacing = { 2 } >
77
+ { navbarItems
78
+ . filter ( ( item ) => ! item . needsLogin || ( item . needsLogin && user ) )
79
+ . map ( ( item ) => (
80
+ < Link
81
+ key = { item . label }
82
+ href = { item . link }
83
+ underline = "none"
84
+ sx = { { color : "common.black" } }
105
85
>
106
- Profile
107
- </ MenuItem >
108
- < MenuItem onClick = { logout } > Logout</ MenuItem >
109
- </ Menu >
110
- </ >
111
- ) : (
112
- < >
113
- < Button variant = "contained" onClick = { ( ) => navigate ( "/signup" ) } >
114
- Sign up
115
- </ Button >
116
- < Button variant = "outlined" onClick = { ( ) => navigate ( "/login" ) } >
117
- Log in
118
- </ Button >
119
- </ >
120
- ) }
121
- </ Stack >
86
+ { path == item . link ? < b > { item . label } </ b > : item . label }
87
+ </ Link >
88
+ ) ) }
89
+ { user ? (
90
+ < >
91
+ < Tooltip title = { "Account settings" } >
92
+ < IconButton onClick = { handleClick } data-testid = "profile" >
93
+ < Avatar src = { user . profilePictureUrl } />
94
+ </ IconButton >
95
+ </ Tooltip >
96
+ < Menu
97
+ anchorEl = { anchorEl }
98
+ open = { ! ! anchorEl }
99
+ onClose = { handleClose }
100
+ onClick = { handleClose }
101
+ >
102
+ < MenuItem
103
+ onClick = { ( ) => {
104
+ handleClose ( ) ;
105
+ navigate ( `/profile/${ user . id } ` ) ;
106
+ } }
107
+ >
108
+ Profile
109
+ </ MenuItem >
110
+ < MenuItem onClick = { logout } > Logout</ MenuItem >
111
+ </ Menu >
112
+ </ >
113
+ ) : (
114
+ < >
115
+ < Button
116
+ variant = "contained"
117
+ onClick = { ( ) => navigate ( "/signup" ) }
118
+ >
119
+ Sign up
120
+ </ Button >
121
+ < Button variant = "outlined" onClick = { ( ) => navigate ( "/login" ) } >
122
+ Log in
123
+ </ Button >
124
+ </ >
125
+ ) }
126
+ </ Stack >
127
+ ) : (
128
+ < Button
129
+ variant = "outlined"
130
+ color = "error"
131
+ onClick = { ( ) => navigate ( "/home" ) }
132
+ >
133
+ Stop matching
134
+ </ Button >
135
+ ) }
122
136
</ Toolbar >
123
137
</ AppMargin >
124
138
</ AppBar >
0 commit comments