8
8
* SPDX-License-Identifier: EPL-2.0
9
9
********************************************************************************/
10
10
11
- import React , { FunctionComponent , PropsWithChildren , useState , useRef } from 'react' ;
12
- import { Theme , Typography , Menu , MenuItem , Link , Button , Accordion , AccordionDetails , AccordionSummary } from '@mui/material' ;
11
+ import React , { FunctionComponent , PropsWithChildren , useState , useRef , useContext } from 'react' ;
12
+ import { Theme , Typography , Menu , MenuItem , Link , Button , Accordion , AccordionDetails , AccordionSummary , IconButton } from '@mui/material' ;
13
13
import { styled } from '@mui/material/styles' ;
14
14
import { Link as RouteLink } from 'react-router-dom' ;
15
15
import ExpandMoreIcon from '@mui/icons-material/ExpandMore' ;
@@ -22,7 +22,11 @@ import PublishIcon from '@mui/icons-material/Publish';
22
22
import GroupWorkIcon from '@mui/icons-material/GroupWork' ;
23
23
import PeopleAltIcon from '@mui/icons-material/PeopleAlt' ;
24
24
import HubIcon from '@mui/icons-material/Hub' ;
25
+ import AccountBoxIcon from '@mui/icons-material/AccountBox' ;
25
26
import { UserSettingsRoutes } from 'openvsx-webui' ;
27
+ import { MainContext } from 'openvsx-webui/lib/context' ;
28
+ import { MobileUserAvatar } from 'openvsx-webui/lib/default/menu-content'
29
+ import { UserAvatar } from 'openvsx-webui/lib/pages/user/avatar' ;
26
30
27
31
//-------------------- Mobile View --------------------//
28
32
@@ -48,7 +52,32 @@ const MobileMenuItemText: FunctionComponent<PropsWithChildren> = ({ children })
48
52
} ;
49
53
50
54
export const MobileMenuContent : FunctionComponent = ( ) => {
55
+ const { service, user} = useContext ( MainContext )
51
56
return < >
57
+ < MobileMenuItem >
58
+ {
59
+ user
60
+ ? < MobileUserAvatar />
61
+ : < RouteLink to = { service . getLoginUrl ( ) } >
62
+ < MobileMenuItemText >
63
+ < AccountBoxIcon sx = { itemIcon } />
64
+ Log In
65
+ </ MobileMenuItemText >
66
+ </ RouteLink >
67
+ }
68
+ </ MobileMenuItem >
69
+ {
70
+ ! location . pathname . startsWith ( UserSettingsRoutes . ROOT )
71
+ ? < MobileMenuItem >
72
+ < RouteLink to = '/user-settings/extensions' >
73
+ < MobileMenuItemText >
74
+ < PublishIcon sx = { itemIcon } />
75
+ Publish Extension
76
+ </ MobileMenuItemText >
77
+ </ RouteLink >
78
+ </ MobileMenuItem >
79
+ : null
80
+ }
52
81
< MobileMenuItem >
53
82
< Link target = '_blank' href = 'https://github.com/eclipse/openvsx' >
54
83
< MobileMenuItemText >
@@ -119,18 +148,6 @@ export const MobileMenuContent: FunctionComponent = () => {
119
148
</ MobileMenuItemText >
120
149
</ RouteLink >
121
150
</ MobileMenuItem >
122
- {
123
- ! location . pathname . startsWith ( UserSettingsRoutes . ROOT )
124
- ? < MobileMenuItem >
125
- < RouteLink to = '/user-settings/extensions' >
126
- < MobileMenuItemText >
127
- < PublishIcon sx = { itemIcon } />
128
- Publish Extension
129
- </ MobileMenuItemText >
130
- </ RouteLink >
131
- </ MobileMenuItem >
132
- : null
133
- }
134
151
</ > ;
135
152
}
136
153
@@ -176,6 +193,7 @@ const SubMenuLink = styled(Link)(subMenuLink);
176
193
177
194
178
195
export const DefaultMenuContent : FunctionComponent = ( ) => {
196
+ const { service, user} = useContext ( MainContext )
179
197
const [ workingGroupMenuOpen , setWorkingGroupMenuOpen ] = useState ( false ) ;
180
198
const workingGroupMenuEl = useRef < HTMLButtonElement | null > ( null ) ;
181
199
const toggleWorkingGroupMenu = ( ) => setWorkingGroupMenuOpen ( ! workingGroupMenuOpen ) ;
@@ -210,5 +228,16 @@ export const DefaultMenuContent: FunctionComponent = () => {
210
228
< Button variant = 'contained' color = 'secondary' href = '/user-settings/extensions' sx = { { mx : 2.5 } } >
211
229
Publish
212
230
</ Button >
231
+ {
232
+ user ?
233
+ < UserAvatar />
234
+ :
235
+ < IconButton
236
+ href = { service . getLoginUrl ( ) }
237
+ title = 'Log In'
238
+ aria-label = 'Log In' >
239
+ < AccountBoxIcon />
240
+ </ IconButton >
241
+ }
213
242
</ > ;
214
243
}
0 commit comments