11import { useNavigate } from 'react-router-dom' ;
22import { useState , useEffect } from 'react' ;
33
4- import List from '@mui/joy/List' ;
5- import Divider from '@mui/joy/Divider' ;
6-
74import {
85 CodeIcon ,
96 GraduationCapIcon ,
@@ -24,14 +21,21 @@ import {
2421 WorkflowIcon ,
2522 UserIcon ,
2623 LogOutIcon ,
24+ LogInIcon ,
2725} from 'lucide-react' ;
2826
2927import { RiImageAiLine } from 'react-icons/ri' ;
3028
3129import {
3230 Box ,
3331 ButtonGroup ,
32+ Divider ,
3433 IconButton ,
34+ List ,
35+ ListItem ,
36+ ListItemButton ,
37+ ListItemContent ,
38+ ListItemDecorator ,
3539 Sheet ,
3640 Tooltip ,
3741 Typography ,
@@ -40,10 +44,13 @@ import {
4044import {
4145 useModelStatus ,
4246 usePluginStatus ,
47+ useAPI ,
48+ logout ,
4349 getFullPath ,
4450} from 'renderer/lib/transformerlab-api-sdk' ;
4551
4652import SelectExperimentMenu from '../Experiment/SelectExperimentMenu' ;
53+ import UserLoginModal from '../User/UserLoginModal' ;
4754
4855import SubNavItem from './SubNavItem' ;
4956import ColorSchemeToggle from './ColorSchemeToggle' ;
@@ -219,11 +226,74 @@ function GlobalMenuItems({ DEV_MODE, experimentInfo, outdatedPluginsCount }) {
219226 ) ;
220227}
221228
229+ function UserDetailsPanel ( { userDetails, mutate } ) {
230+ return (
231+ < >
232+ < UserIcon />
233+ < Box sx = { { minWidth : 0 , flex : 1 } } >
234+ < Typography
235+ level = "title-sm"
236+ sx = { {
237+ whiteSpace : 'nowrap' ,
238+ overflow : 'hidden' ,
239+ textOverflow : 'ellipsis' ,
240+ } }
241+ >
242+ { userDetails ?. name }
243+ </ Typography >
244+ < Typography
245+ level = "body-xs"
246+ sx = { {
247+ whiteSpace : 'nowrap' ,
248+ overflow : 'hidden' ,
249+ textOverflow : 'ellipsis' ,
250+ } }
251+ >
252+ { userDetails ?. email }
253+ </ Typography >
254+ </ Box >
255+
256+ < IconButton
257+ size = "sm"
258+ variant = "plain"
259+ color = "neutral"
260+ sx = { {
261+ cursor : 'pointer' ,
262+ '&:hover' : {
263+ backgroundColor : 'var(--joy-palette-neutral-100)' ,
264+ borderRadius : 'sm' ,
265+ } ,
266+ } }
267+ >
268+ < LogOutIcon
269+ size = "18px"
270+ onClick = { async ( ) => {
271+ await logout ( ) ;
272+ mutate ( ) ;
273+ alert ( 'User logged out.' ) ;
274+ } }
275+ />
276+ </ IconButton >
277+ </ >
278+ ) ;
279+ }
280+
222281function BottomMenuItems ( { DEV_MODE , navigate, themeSetter } ) {
282+ const [ userLoginModalOpen , setUserLoginModalOpen ] = useState ( false ) ;
283+ const {
284+ data : userInfo ,
285+ error : userError ,
286+ isLoading : userLoading ,
287+ mutate : userMutate ,
288+ } = useAPI ( 'users' , [ 'me' ] , { } ) ;
289+
290+ if ( userError ) {
291+ console . log ( userError ) ;
292+ }
293+
223294 return (
224295 < >
225- { ' ' }
226- < Divider sx = { { my : 2 } } />
296+ < Divider sx = { { my : 1 } } />
227297 < Box
228298 sx = { {
229299 display : DEV_MODE ? 'flex' : 'none' ,
@@ -233,37 +303,38 @@ function BottomMenuItems({ DEV_MODE, navigate, themeSetter }) {
233303 maxWidth : '180px' ,
234304 } }
235305 >
236- { /* <Avatar
237- variant="outlined"
238- size="sm"
239- src="https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?auto=format&fit=crop&w=286"
240- /> */ }
241- < UserIcon />
242- < Box sx = { { minWidth : 0 , flex : 1 } } >
243- < Typography
244- level = "title-sm"
245- sx = { {
246- whiteSpace : 'nowrap' ,
247- overflow : 'hidden' ,
248- textOverflow : 'ellipsis' ,
249- } }
250- >
251- User Name
252- </ Typography >
253- < Typography
254- level = "body-xs"
306+ { userInfo && userInfo . id ? (
307+ < UserDetailsPanel userDetails = { userInfo } mutate = { userMutate } />
308+ ) : (
309+ < List
255310 sx = { {
256- whiteSpace : 'nowrap' ,
257- overflow : 'hidden' ,
258- textOverflow : 'ellipsis' ,
311+ '--ListItem-radius' : '6px' ,
312+ '--ListItem-minHeight' : '32px' ,
313+ overflowY : 'auto' ,
314+ flex : 1 ,
259315 } }
260316 >
261- 262- </ Typography >
263- </ Box >
264- < IconButton size = "sm" variant = "plain" color = "neutral" >
265- < LogOutIcon size = "18px" />
266- </ IconButton >
317+ < ListItem className = "FirstSidebar_Content" >
318+ < ListItemButton
319+ variant = "plain"
320+ onClick = { ( ) => setUserLoginModalOpen ( true ) }
321+ >
322+ < ListItemDecorator sx = { { minInlineSize : '30px' } } >
323+ < LogInIcon />
324+ </ ListItemDecorator >
325+ < ListItemContent
326+ sx = { {
327+ display : 'flex' ,
328+ justifyContent : 'flex-start' ,
329+ alignContent : 'center' ,
330+ } }
331+ >
332+ < Typography level = "body-sm" > Login</ Typography >
333+ </ ListItemContent >
334+ </ ListItemButton >
335+ </ ListItem >
336+ </ List >
337+ ) }
267338 </ Box >
268339 < ButtonGroup
269340 sx = { {
@@ -301,6 +372,13 @@ src="https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?auto=format&fi
301372 </ IconButton >
302373 </ Tooltip >
303374 </ ButtonGroup >
375+ < UserLoginModal
376+ open = { userLoginModalOpen }
377+ onClose = { ( ) => {
378+ setUserLoginModalOpen ( false ) ;
379+ userMutate ( ) ;
380+ } }
381+ />
304382 </ >
305383 ) ;
306384}
0 commit comments