@@ -4,12 +4,19 @@ import type { ExcalidrawImperativeAPI } from '@atyrode/excalidraw/types';
44import type { MainMenu as MainMenuType } from '@atyrode/excalidraw' ;
55
66import { LogOut , SquarePlus , LayoutDashboard , SquareCode , Eye , Coffee , Grid2x2 , User , Text , ArchiveRestore , Settings , Terminal } from 'lucide-react' ;
7+ import AccountDialog from './AccountDialog' ;
8+ import md5 from 'crypto-js/md5' ;
79import { capture } from '../utils/posthog' ;
810import { ExcalidrawElementFactory , PlacementMode } from '../lib/ExcalidrawElementFactory' ;
911import { useUserProfile } from "../api/hooks" ;
1012import { queryClient } from "../api/queryClient" ;
11- import SettingsDialog from "./SettingsDialog" ;
1213import "./MainMenu.scss" ;
14+
15+ // Function to generate gravatar URL
16+ const getGravatarUrl = ( email : string , size = 32 ) => {
17+ const hash = md5 ( email . toLowerCase ( ) . trim ( ) ) . toString ( ) ;
18+ return `https://www.gravatar.com/avatar/${ hash } ?s=${ size } &d=identicon` ;
19+ } ;
1320interface MainMenuConfigProps {
1421 MainMenu : typeof MainMenuType ;
1522 excalidrawAPI : ExcalidrawImperativeAPI | null ;
@@ -22,20 +29,21 @@ interface MainMenuConfigProps {
2229export const MainMenuConfig : React . FC < MainMenuConfigProps > = ( {
2330 MainMenu,
2431 excalidrawAPI,
25- showBackupsModal,
2632 setShowBackupsModal,
27- showSettingsModal = false ,
2833 setShowSettingsModal = ( show : boolean ) => { } ,
2934} ) => {
35+ const [ showAccountModal , setShowAccountModal ] = useState ( false ) ;
3036 const { data, isLoading, isError } = useUserProfile ( ) ;
3137
3238 let username = "" ;
39+ let email = "" ;
3340 if ( isLoading ) {
3441 username = "Loading..." ;
3542 } else if ( isError || ! data ?. username ) {
3643 username = "Unknown" ;
3744 } else {
3845 username = data . username ;
46+ email = data . email || "" ;
3947 }
4048 const handleHtmlEditorClick = ( ) => {
4149 if ( ! excalidrawAPI ) return ;
@@ -124,6 +132,10 @@ export const MainMenuConfig: React.FC<MainMenuConfigProps> = ({
124132 const handleSettingsClick = ( ) => {
125133 setShowSettingsModal ( true ) ;
126134 } ;
135+
136+ const handleAccountClick = ( ) => {
137+ setShowAccountModal ( true ) ;
138+ } ;
127139
128140 const handleGridToggle = ( ) => {
129141 if ( ! excalidrawAPI ) return ;
@@ -155,13 +167,29 @@ export const MainMenuConfig: React.FC<MainMenuConfigProps> = ({
155167 } ;
156168
157169 return (
158- < MainMenu >
159- < div className = "main-menu__top-row" >
160- < span className = "main-menu__label" >
161- < User width = { 20 } height = { 20 } />
162- < span className = "main-menu__label-username" > { username } </ span >
163- </ span >
164- </ div >
170+ < >
171+ { showAccountModal && (
172+ < AccountDialog
173+ excalidrawAPI = { excalidrawAPI }
174+ onClose = { ( ) => setShowAccountModal ( false ) }
175+ />
176+ ) }
177+ < MainMenu >
178+ < div className = "main-menu__top-row" >
179+ < span className = "main-menu__label" style = { { gap : 0.2 } } >
180+ { email && (
181+ < img
182+ src = { getGravatarUrl ( email ) }
183+ alt = { username }
184+ className = "main-menu__gravatar"
185+ width = { 20 }
186+ height = { 20 }
187+ style = { { borderRadius : '50%' , marginRight : '8px' } }
188+ />
189+ ) }
190+ < span className = "main-menu__label-username" > { username } </ span >
191+ </ span >
192+ </ div >
165193 < MainMenu . Separator />
166194
167195 < MainMenu . Group title = "Files" >
@@ -238,6 +266,13 @@ export const MainMenuConfig: React.FC<MainMenuConfigProps> = ({
238266
239267 < MainMenu . Separator />
240268
269+ < MainMenu . Item
270+ icon = { < User /> }
271+ onClick = { handleAccountClick }
272+ >
273+ Account
274+ </ MainMenu . Item >
275+
241276 < MainMenu . Item
242277 icon = { < Settings /> }
243278 onClick = { handleSettingsClick }
@@ -274,5 +309,6 @@ export const MainMenuConfig: React.FC<MainMenuConfigProps> = ({
274309 </ MainMenu . Item >
275310
276311 </ MainMenu >
312+ </ >
277313 ) ;
278314} ;
0 commit comments