Skip to content

Commit f4e2a9e

Browse files
committed
feat: enhance MainMenu with user account functionality
- Added AccountDialog component to display user account information. - Integrated Gravatar for user avatars based on email. - Implemented account modal toggle in MainMenu for improved user experience. - Updated user profile handling to include email for avatar generation.
1 parent 4ebc7ef commit f4e2a9e

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

src/frontend/src/ui/MainMenu.tsx

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ import type { ExcalidrawImperativeAPI } from '@atyrode/excalidraw/types';
44
import type { MainMenu as MainMenuType } from '@atyrode/excalidraw';
55

66
import { 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';
79
import { capture } from '../utils/posthog';
810
import { ExcalidrawElementFactory, PlacementMode } from '../lib/ExcalidrawElementFactory';
911
import { useUserProfile } from "../api/hooks";
1012
import { queryClient } from "../api/queryClient";
11-
import SettingsDialog from "./SettingsDialog";
1213
import "./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+
};
1320
interface MainMenuConfigProps {
1421
MainMenu: typeof MainMenuType;
1522
excalidrawAPI: ExcalidrawImperativeAPI | null;
@@ -22,20 +29,21 @@ interface MainMenuConfigProps {
2229
export 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

Comments
 (0)