Skip to content

Commit 85948af

Browse files
committed
Enhance Excalidraw app: add keyboard shortcut for connection dialog and integrate server settings in the main menu. Update app structure to conditionally render connection dialog based on server configuration.
1 parent 5d3c024 commit 85948af

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

excalidraw-app/src/App.tsx

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,50 @@ function App() {
99
const [serverConfig, setServerConfig] = useState<ServerConfig | null>(null);
1010

1111
useEffect(() => {
12-
// Check if we have a saved config
13-
const config = getServerConfig();
14-
if (config.enabled !== undefined) {
12+
// Check if we have a saved config in localStorage
13+
const saved = localStorage.getItem('excalidraw-server-config');
14+
if (saved) {
1515
// User has made a choice before, skip dialog
16+
const config = getServerConfig();
1617
setServerConfig(config);
1718
setShowDialog(false);
1819
}
20+
21+
// Add keyboard shortcut to open connection dialog (Cmd/Ctrl + K)
22+
const handleKeyDown = (e: KeyboardEvent) => {
23+
if ((e.metaKey || e.ctrlKey) && e.key === 'k') {
24+
e.preventDefault();
25+
setShowDialog(true);
26+
}
27+
};
28+
29+
window.addEventListener('keydown', handleKeyDown);
30+
return () => window.removeEventListener('keydown', handleKeyDown);
1931
}, []);
2032

2133
const handleConnect = (config: ServerConfig) => {
2234
setServerConfig(config);
2335
setShowDialog(false);
2436
};
2537

26-
if (showDialog || !serverConfig) {
38+
if (!serverConfig) {
2739
return <ConnectionDialog onConnect={handleConnect} onClose={() => setShowDialog(false)} />;
2840
}
2941

30-
return <ExcalidrawWrapper serverConfig={serverConfig} />;
42+
return (
43+
<>
44+
<ExcalidrawWrapper
45+
serverConfig={serverConfig}
46+
onOpenSettings={() => setShowDialog(true)}
47+
/>
48+
{showDialog && (
49+
<ConnectionDialog
50+
onConnect={handleConnect}
51+
onClose={() => setShowDialog(false)}
52+
/>
53+
)}
54+
</>
55+
);
3156
}
3257

3358
export default App;

excalidraw-app/src/components/ExcalidrawWrapper.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import { Excalidraw } from '@excalidraw/excalidraw';
1+
import { Excalidraw, MainMenu } from '@excalidraw/excalidraw';
22
import { ExcalidrawImperativeAPI } from '@excalidraw/excalidraw/types/types';
33
import { useEffect, useRef, useState } from 'react';
44
import { ExcalidrawAPI, ServerConfig } from '../lib/api';
55
import { localStorage as localStorageAPI } from '../lib/storage';
66
import '@excalidraw/excalidraw/index.css';
7+
78
interface ExcalidrawWrapperProps {
89
serverConfig: ServerConfig;
10+
onOpenSettings: () => void;
911
}
1012

11-
export function ExcalidrawWrapper({ serverConfig }: ExcalidrawWrapperProps) {
13+
export function ExcalidrawWrapper({ serverConfig, onOpenSettings }: ExcalidrawWrapperProps) {
1214
const excalidrawRef = useRef<ExcalidrawImperativeAPI>(null);
1315
const [api, setApi] = useState<ExcalidrawAPI | null>(null);
1416
const [currentDrawingId, setCurrentDrawingId] = useState<string | null>(null);
@@ -103,7 +105,21 @@ export function ExcalidrawWrapper({ serverConfig }: ExcalidrawWrapperProps) {
103105
ref={excalidrawRef}
104106
onChange={handleChange}
105107
theme="light"
106-
/>
108+
>
109+
<MainMenu>
110+
<MainMenu.DefaultItems.LoadScene />
111+
<MainMenu.DefaultItems.SaveToActiveFile />
112+
<MainMenu.DefaultItems.Export />
113+
<MainMenu.DefaultItems.SaveAsImage />
114+
<MainMenu.Separator />
115+
<MainMenu.Item onSelect={onOpenSettings}>
116+
🔌 Server Settings
117+
</MainMenu.Item>
118+
<MainMenu.Separator />
119+
<MainMenu.DefaultItems.Help />
120+
<MainMenu.DefaultItems.ClearCanvas />
121+
</MainMenu>
122+
</Excalidraw>
107123
</div>
108124
);
109125
}

0 commit comments

Comments
 (0)