Skip to content

Commit 7b387fc

Browse files
committed
refactor: update App and MainMenu components for settings management
- Removed unused state and handlers related to the SettingsDialog in App.tsx to streamline the component. - Added state management and conditional rendering for SettingsDialog in MainMenu.tsx, enhancing user experience and functionality.
1 parent 19df229 commit 7b387fc

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

src/frontend/src/App.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useAppConfig } from "./hooks/useAppConfig";
1313
import DiscordButton from './ui/DiscordButton';
1414
import { MainMenuConfig } from './ui/MainMenu';
1515
import AuthDialog from './ui/AuthDialog';
16-
import SettingsDialog from './ui/SettingsDialog';
16+
// import SettingsDialog from './ui/SettingsDialog'; // Removed import
1717
import Collab from './lib/collab/Collab';
1818

1919
// Utils
@@ -39,13 +39,14 @@ export default function App() {
3939
leaveSharedPad
4040
} = usePadTabs(isAuthenticated);
4141

42-
const [showSettingsModal, setShowSettingsModal] = useState(false);
42+
// const [showSettingsModal, setShowSettingsModal] = useState(false); // Removed state
43+
const [showPadsModal, setShowPadsModal] = useState(false); // Added state for PadsModal
4344
const [excalidrawAPI, excalidrawRefCallback] = useCallbackRefState<ExcalidrawImperativeAPI>();
4445

4546

46-
const handleCloseSettingsModal = () => {
47-
setShowSettingsModal(false);
48-
};
47+
// const handleCloseSettingsModal = () => { // Removed handler
48+
// setShowSettingsModal(false);
49+
// };
4950

5051
const handleOnScrollChange = () => {
5152
lockEmbeddables(excalidrawAPI?.getAppState());
@@ -84,19 +85,10 @@ export default function App() {
8485
<MainMenuConfig
8586
MainMenu={MainMenu}
8687
excalidrawAPI={excalidrawAPI}
87-
showSettingsModal={showSettingsModal}
88-
setShowSettingsModal={setShowSettingsModal}
8988
/>
9089

9190
{!isLoadingAuth && !isAuthenticated && (
92-
<AuthDialog onClose={() => { }} />
93-
)}
94-
95-
{showSettingsModal && (
96-
<SettingsDialog
97-
excalidrawAPI={excalidrawAPI}
98-
onClose={handleCloseSettingsModal}
99-
/>
91+
<AuthDialog />
10092
)}
10193

10294
{excalidrawAPI && (

src/frontend/src/ui/MainMenu.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import type { MainMenu as MainMenuType } from '@atyrode/excalidraw';
66
import { LogOut, SquarePlus, LayoutDashboard, User, Text, Settings, Terminal, FileText, FlaskConical } from 'lucide-react';
77
import md5 from 'crypto-js/md5';
88

9+
// Components
10+
import SettingsDialog from './SettingsDialog'; // Added import
11+
912
import { useLogout } from '../hooks/useLogout';
1013
import { useAuthStatus } from '../hooks/useAuthStatus';
1114

@@ -25,19 +28,15 @@ const getGravatarUrl = (email: string, size = 32) => {
2528
interface MainMenuConfigProps {
2629
MainMenu: typeof MainMenuType;
2730
excalidrawAPI: ExcalidrawImperativeAPI | null;
28-
showPadsModal: boolean;
29-
setShowPadsModal: (show: boolean) => void;
30-
showSettingsModal?: boolean;
31-
setShowSettingsModal?: (show: boolean) => void;
3231
}
3332

3433
export const MainMenuConfig: React.FC<MainMenuConfigProps> = ({
3534
MainMenu,
3635
excalidrawAPI,
37-
setShowPadsModal,
38-
setShowSettingsModal = (show: boolean) => {},
3936
}) => {
4037
const [showAccountModal, setShowAccountModal] = useState(false);
38+
const [showSettingsModal, setShowSettingsModal] = useState(false);
39+
4140
const { mutate: logoutMutation, isPending: isLoggingOut } = useLogout();
4241
const { user, isLoading, isError } = useAuthStatus();
4342

@@ -132,13 +131,13 @@ export const MainMenuConfig: React.FC<MainMenuConfigProps> = ({
132131
});
133132
};
134133

135-
const handleManagePadsClick = () => {
136-
setShowPadsModal(true);
137-
};
138-
139134
const handleSettingsClick = () => {
140135
setShowSettingsModal(true);
141136
};
137+
138+
const handleCloseSettingsModal = () => { // Added handler to close settings modal
139+
setShowSettingsModal(false);
140+
};
142141

143142
const handleAccountClick = () => {
144143
setShowAccountModal(true);
@@ -205,6 +204,12 @@ export const MainMenuConfig: React.FC<MainMenuConfigProps> = ({
205204
onClose={() => setShowAccountModal(false)}
206205
/>
207206
)}
207+
{showSettingsModal && ( // Added conditional rendering for SettingsDialog
208+
<SettingsDialog
209+
excalidrawAPI={excalidrawAPI}
210+
onClose={handleCloseSettingsModal}
211+
/>
212+
)}
208213
<MainMenu>
209214
<div className="main-menu__top-row">
210215
<span className="main-menu__label" style={{ gap: 0.2 }}>
@@ -227,12 +232,6 @@ export const MainMenuConfig: React.FC<MainMenuConfigProps> = ({
227232
<MainMenu.DefaultItems.LoadScene />
228233
<MainMenu.DefaultItems.Export />
229234
<MainMenu.DefaultItems.SaveAsImage />
230-
<MainMenu.Item
231-
icon={<FileText />}
232-
onClick={handleManagePadsClick}
233-
>
234-
Manage pads...
235-
</MainMenu.Item>
236235
<MainMenu.DefaultItems.ClearCanvas />
237236
</MainMenu.Group>
238237

0 commit comments

Comments
 (0)