From b7315daa7e6817f97ef4bc62270a4f73e62a35e1 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Fri, 6 Feb 2026 21:56:28 -0500 Subject: [PATCH] Refactor settings dialog to use URL-based state management with tab synchronization --- frontend/src/App.tsx | 4 +- .../components/settings/SettingsDialog.tsx | 124 ++++++++++-------- frontend/src/components/ui/dialog.tsx | 4 +- frontend/src/components/ui/header.tsx | 8 +- frontend/src/contexts/AuthContext.tsx | 2 - frontend/src/hooks/useSettingsDialog.ts | 16 +-- frontend/src/hooks/useSettingsDialogUrl.ts | 60 +++++++++ 7 files changed, 140 insertions(+), 78 deletions(-) create mode 100644 frontend/src/hooks/useSettingsDialogUrl.ts diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index df5f0de4..38da32ae 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -9,7 +9,6 @@ import { Login } from './pages/Login' import { Register } from './pages/Register' import { Setup } from './pages/Setup' import { SettingsDialog } from './components/settings/SettingsDialog' -import { useSettingsDialog } from './hooks/useSettingsDialog' import { useTheme } from './hooks/useTheme' import { TTSProvider } from './contexts/TTSContext' import { AuthProvider } from './contexts/AuthContext' @@ -49,7 +48,6 @@ function PermissionDialogWrapper() { } function AppShell() { - const { isOpen, close } = useSettingsDialog() useTheme() useEffect(() => { @@ -66,7 +64,7 @@ function AppShell() { - + void -} +import { useSettingsDialog } from '@/hooks/useSettingsDialog' type SettingsView = 'menu' | 'general' | 'git' | 'shortcuts' | 'opencode' | 'providers' | 'account' | 'voice' | 'notifications' -export function SettingsDialog({ open, onOpenChange }: SettingsDialogProps) { +export function SettingsDialog() { + const { isOpen, close, activeTab, setActiveTab } = useSettingsDialog() const [mobileView, setMobileView] = useState('menu') const contentRef = useRef(null) const handleSwipeBack = useCallback(() => { if (mobileView === 'menu') { setMobileView('menu') - onOpenChange(false) + close() } else { setMobileView('menu') } - }, [mobileView, onOpenChange]) + }, [mobileView, close]) const { bind: bindSwipe, swipeStyles } = useSwipeBack(handleSwipeBack, { - enabled: open, + enabled: isOpen, }) useEffect(() => { return bindSwipe(contentRef.current) }, [bindSwipe]) + useEffect(() => { + if (!isOpen) return + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === 'Escape') close() + } + document.addEventListener('keydown', handleKeyDown) + return () => document.removeEventListener('keydown', handleKeyDown) + }, [isOpen, close]) + const menuItems = [ { id: 'account', icon: User, label: 'Account', description: 'Profile, passkeys, and sign out' }, { id: 'general', icon: Settings2, label: 'General Settings', description: 'App preferences and behavior' }, @@ -52,26 +58,33 @@ export function SettingsDialog({ open, onOpenChange }: SettingsDialogProps) { { id: 'providers', icon: Key, label: 'Providers', description: 'Manage AI provider API keys' }, ] - const handleClose = () => { - setMobileView('menu') - onOpenChange(false) + const handleTabChange = (tab: string) => { + setActiveTab(tab as SettingsView) } - return ( - - - -
-
-

- Settings -

-
- + return ( + + +
+
+

+ Settings +

+ +
+
@@ -117,31 +130,31 @@ export function SettingsDialog({ open, onOpenChange }: SettingsDialogProps) {
-
-
- {mobileView !== 'menu' && ( - - )} -

- {mobileView === 'menu' ? 'Settings' : menuItems.find(item => item.id === mobileView)?.label} -

-
- -
+
+
+ {mobileView !== 'menu' && ( + + )} +

+ {mobileView === 'menu' ? 'Settings' : menuItems.find(item => item.id === mobileView)?.label} +

+
+ +
{mobileView === 'menu' && ( @@ -149,7 +162,10 @@ export function SettingsDialog({ open, onOpenChange }: SettingsDialogProps) { {menuItems.map((item) => (