Skip to content

Commit 250de02

Browse files
authored
refactor: use Excalidraw Dialog instead of custom modal (#30)
* chore: update package dependencies - Bumped version of @atyrode/excalidraw from 0.18.0-1 to 0.18.0-2. - Updated @tanstack/query-core and @tanstack/react-query to versions 5.74.4 and 5.74.6 respectively. - Updated @types/node to version 22.15.1 and posthog-js to version 1.236.6 in yarn.lock. * feat: integrate authentication modal into ExcalidrawWrapper - Added authentication handling to ExcalidrawWrapper, displaying AuthModal when the user is not authenticated. - Removed AuthModal state management from AuthGate, simplifying its structure. - Updated AuthModal to use the Dialog component for improved UI consistency. * refactor: replace AuthModal with AuthDialog and update MainMenu - Replaced AuthModal with a new AuthDialog component for improved functionality and clarity. - Updated ExcalidrawWrapper to use AuthDialog, simplifying the authentication flow. - Removed the old AuthModal file. * feat: add new icon components for Discord, GitHub, and Google - Introduced DiscordIcon, GithubIcon, and GoogleIcon components. - Each icon component supports customizable properties such as className, width, height, and fill/stroke colors. - Updated index.ts to export the new icon components for easy access. * feat: add AuthDialog styles and update component references - Introduced AuthDialog.scss for styling the authentication modal, enhancing the UI with a structured layout and responsive design. - Updated AuthDialog component to use new styles and replaced references from AuthModal to AuthDialog. - Integrated new icon components (GoogleIcon, GithubIcon, DiscordIcon) for improved visual consistency in the authentication buttons. * refactor: remove Modal component and update styles - Deleted the Modal component and its associated styles to streamline the codebase. - Updated AuthDialog.scss to include necessary styles for the authentication modal. - Enhanced index.scss with new styles for fullscreen dialogs and modal backgrounds. * feat: enhance AuthDialog with new styles and speech bubble - Updated AuthDialog.scss to improve layout and responsiveness, including new animations for the logo and speech bubble. - Modified AuthDialog component to display a random greeting message from a predefined list. - Adjusted styles in index.scss for modal backgrounds to enhance visual consistency. - Improved button styles and layout within the authentication modal for better user experience. * fix: correct punctuation in AuthDialog description * fix: correct spelling in warning text of AuthDialog component * refactor: switch DiscordButton to new icon
1 parent 7eb1027 commit 250de02

18 files changed

+594
-622
lines changed

src/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"private": true,
55
"dependencies": {
6-
"@atyrode/excalidraw": "^0.18.0-1",
6+
"@atyrode/excalidraw": "^0.18.0-2",
77
"@monaco-editor/react": "^4.7.0",
88
"@tanstack/react-query": "^5.74.3",
99
"@tanstack/react-query-devtools": "^5.74.3",

src/frontend/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ export default function App({
125125
setExcalidrawAPI={setExcalidrawAPI}
126126
onChange={debouncedLogChange}
127127
MainMenu={MainMenu}
128+
isAuthenticated={isAuthenticated}
129+
isAuthLoading={isAuthLoading}
128130
>
129131
{children}
130132
</ExcalidrawWrapper>

src/frontend/src/AuthGate.tsx

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useEffect, useRef, useState } from "react";
22
import { useAuthCheck } from "./api/hooks";
3-
import AuthModal from "./ui/AuthModal";
43

54
/**
65
* If unauthenticated, it shows the AuthModal as an overlay, but still renders the app behind it.
@@ -50,37 +49,6 @@ export default function AuthGate({ children }: { children: React.ReactNode }) {
5049
// eslint-disable-next-line react-hooks/exhaustive-deps
5150
}, [isAuthenticated, coderAuthDone]);
5251

53-
// State to control modal visibility and exit animation
54-
const [showAuthModal, setShowAuthModal] = useState(false);
55-
const [isExiting, setIsExiting] = useState(false);
56-
57-
// Update showAuthModal when authentication status changes
58-
useEffect(() => {
59-
if (isAuthenticated === false) {
60-
setShowAuthModal(true);
61-
setIsExiting(false);
62-
} else if (isAuthenticated === true && showAuthModal) {
63-
// Start exit animation when user becomes authenticated
64-
setIsExiting(true);
65-
// Modal will be removed after animation completes via onExitComplete
66-
}
67-
}, [isAuthenticated, showAuthModal]);
68-
69-
// Handle exit animation completion
70-
const handleExitComplete = () => {
71-
setShowAuthModal(false);
72-
};
73-
74-
// Always render children; overlay AuthModal if not authenticated
75-
return (
76-
<>
77-
{children}
78-
{showAuthModal && (
79-
<AuthModal
80-
isExiting={isExiting}
81-
onExitComplete={handleExitComplete}
82-
/>
83-
)}
84-
</>
85-
);
52+
// Just render children - AuthModal is now handled by ExcalidrawWrapper
53+
return <>{children}</>;
8654
}

src/frontend/src/ExcalidrawWrapper.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React, { Children, cloneElement } from 'react';
1+
import React, { Children, cloneElement, useState, useEffect } from 'react';
22
import DiscordButton from './ui/DiscordButton';
33
import FeedbackButton from './ui/FeedbackButton';
44
import type { ExcalidrawImperativeAPI } from '@atyrode/excalidraw/types';
55
import type { NonDeletedExcalidrawElement } from '@atyrode/excalidraw/element/types';
66
import type { AppState } from '@atyrode/excalidraw/types';
77
import { MainMenuConfig } from './ui/MainMenu';
88
import { renderCustomEmbeddable } from './CustomEmbeddableRenderer';
9+
import AuthDialog from './ui/AuthDialog';
910

1011
const defaultInitialData = {
1112
elements: [],
@@ -25,6 +26,8 @@ interface ExcalidrawWrapperProps {
2526
onChange: (elements: NonDeletedExcalidrawElement[], state: AppState) => void;
2627
MainMenu: any;
2728
renderTopRightUI?: () => React.ReactNode;
29+
isAuthenticated?: boolean | null;
30+
isAuthLoading?: boolean;
2831
}
2932

3033
export const ExcalidrawWrapper: React.FC<ExcalidrawWrapperProps> = ({
@@ -35,7 +38,19 @@ export const ExcalidrawWrapper: React.FC<ExcalidrawWrapperProps> = ({
3538
onChange,
3639
MainMenu,
3740
renderTopRightUI,
41+
isAuthenticated = null,
42+
isAuthLoading = false,
3843
}) => {
44+
// Add state for modal animation
45+
const [isExiting, setIsExiting] = useState(false);
46+
47+
// Handle auth state changes
48+
useEffect(() => {
49+
if (isAuthenticated === true) {
50+
setIsExiting(true);
51+
}
52+
}, [isAuthenticated]);
53+
3954
const renderExcalidraw = (children: React.ReactNode) => {
4055
const Excalidraw = Children.toArray(children).find(
4156
(child: any) =>
@@ -65,7 +80,14 @@ export const ExcalidrawWrapper: React.FC<ExcalidrawWrapperProps> = ({
6580
</div>
6681
)),
6782
},
68-
<MainMenuConfig MainMenu={MainMenu} excalidrawAPI={excalidrawAPI} />
83+
<>
84+
<MainMenuConfig MainMenu={MainMenu} excalidrawAPI={excalidrawAPI} />
85+
{!isAuthLoading && isAuthenticated === false && (
86+
<AuthDialog
87+
onClose={() => {}}
88+
/>
89+
)}
90+
</>
6991
);
7092
};
7193

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from "react";
2+
3+
interface DiscordIconProps {
4+
className?: string;
5+
width?: number;
6+
height?: number;
7+
fill?: string;
8+
}
9+
10+
export const DiscordIcon: React.FC<DiscordIconProps> = ({
11+
className = "",
12+
width = 20,
13+
height = 20,
14+
fill = "currentColor",
15+
}) => {
16+
return (
17+
<svg
18+
width={width}
19+
height={height}
20+
viewBox="0 0 71 55"
21+
fill="none"
22+
xmlns="http://www.w3.org/2000/svg"
23+
className={className}
24+
>
25+
<path
26+
d="M60.1045 4.8978C55.5792 2.8214 50.7265 1.2916 45.6527 0.41542C45.5603 0.39851 45.468 0.440769 45.4204 0.525289C44.7963 1.6353 44.105 3.0834 43.6209 4.2216C38.1637 3.4046 32.7345 3.4046 27.3892 4.2216C26.905 3.0581 26.1886 1.6353 25.5617 0.525289C25.5141 0.443589 25.4218 0.40133 25.3294 0.41542C20.2584 1.2888 15.4057 2.8186 10.8776 4.8978C10.8384 4.9147 10.8048 4.9429 10.7825 4.9795C1.57795 18.7309 -0.943561 32.1443 0.293408 45.3914C0.299005 45.4562 0.335386 45.5182 0.385761 45.5576C6.45866 50.0174 12.3413 52.7249 18.1147 54.5195C18.2071 54.5477 18.305 54.5139 18.3638 54.4378C19.7295 52.5728 20.9469 50.6063 21.9907 48.5383C22.0523 48.4172 21.9935 48.2735 21.8676 48.2256C19.9366 47.4931 18.0979 46.6 16.3292 45.5858C16.1893 45.5041 16.1781 45.304 16.3068 45.2082C16.679 44.9293 17.0513 44.6391 17.4067 44.3461C17.471 44.2926 17.5606 44.2813 17.6362 44.3151C29.2558 49.6202 41.8354 49.6202 53.3179 44.3151C53.3935 44.2785 53.4831 44.2898 53.5502 44.3433C53.9057 44.6363 54.2779 44.9293 54.6529 45.2082C54.7816 45.304 54.7732 45.5041 54.6333 45.5858C52.8646 46.6197 51.0259 47.4931 49.0921 48.2228C48.9662 48.2707 48.9102 48.4172 48.9718 48.5383C50.038 50.6034 51.2554 52.5699 52.5959 54.435C52.6519 54.5139 52.7526 54.5477 52.845 54.5195C58.6464 52.7249 64.529 50.0174 70.6019 45.5576C70.6551 45.5182 70.6887 45.459 70.6943 45.3942C72.1747 30.0791 68.2147 16.7757 60.1968 4.9823C60.1772 4.9429 60.1437 4.9147 60.1045 4.8978ZM23.7259 37.3253C20.2276 37.3253 17.3451 34.1136 17.3451 30.1693C17.3451 26.225 20.1717 23.0133 23.7259 23.0133C27.308 23.0133 30.1626 26.2532 30.1066 30.1693C30.1066 34.1136 27.28 37.3253 23.7259 37.3253ZM47.3178 37.3253C43.8196 37.3253 40.9371 34.1136 40.9371 30.1693C40.9371 26.225 43.7636 23.0133 47.3178 23.0133C50.9 23.0133 53.7545 26.2532 53.6986 30.1693C53.6986 34.1136 50.9 37.3253 47.3178 37.3253Z"
27+
fill={fill}
28+
/>
29+
</svg>
30+
);
31+
};
32+
33+
export default DiscordIcon;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from "react";
2+
3+
interface GithubIconProps {
4+
className?: string;
5+
width?: number;
6+
height?: number;
7+
stroke?: string;
8+
strokeWidth?: number;
9+
}
10+
11+
export const GithubIcon: React.FC<GithubIconProps> = ({
12+
className = "",
13+
width = 20,
14+
height = 20,
15+
stroke = "currentColor",
16+
strokeWidth = 2,
17+
}) => {
18+
return (
19+
<svg
20+
xmlns="http://www.w3.org/2000/svg"
21+
width={width}
22+
height={height}
23+
viewBox="0 0 24 24"
24+
fill="none"
25+
stroke={stroke}
26+
strokeWidth={strokeWidth}
27+
strokeLinecap="round"
28+
strokeLinejoin="round"
29+
className={className}
30+
>
31+
<path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4" />
32+
<path d="M9 18c-4.51 2-5-2-7-2" />
33+
</svg>
34+
);
35+
};
36+
37+
export default GithubIcon;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from "react";
2+
3+
interface GoogleIconProps {
4+
className?: string;
5+
width?: number;
6+
height?: number;
7+
}
8+
9+
export const GoogleIcon: React.FC<GoogleIconProps> = ({
10+
className = "",
11+
width = 20,
12+
height = 20,
13+
}) => {
14+
return (
15+
<svg
16+
className={className}
17+
width={width}
18+
height={height}
19+
viewBox="0 0 24 24"
20+
fill="currentColor"
21+
>
22+
<path
23+
d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"
24+
fill="#4285F4"
25+
/>
26+
<path
27+
d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"
28+
fill="#34A853"
29+
/>
30+
<path
31+
d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"
32+
fill="#FBBC05"
33+
/>
34+
<path
35+
d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"
36+
fill="#EA4335"
37+
/>
38+
<path d="M1 1h22v22H1z" fill="none" />
39+
</svg>
40+
);
41+
};
42+
43+
export default GoogleIcon;

src/frontend/src/icons/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { default as GoogleIcon } from './GoogleIcon';
2+
export { default as GithubIcon } from './GithubIcon';
3+
export { default as DiscordIcon } from './DiscordIcon';

0 commit comments

Comments
 (0)