diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 2817b5ba..b4df3cde 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,7 +1,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { createBrowserRouter, RouterProvider, Outlet, useNavigate, useLocation } from 'react-router-dom' -import { useEffect, useRef } from 'react' +import { useEffect, useRef, useCallback } from 'react' import { Toaster } from 'sonner' import { Repos } from './pages/Repos' import { RepoDetail } from './pages/RepoDetail' @@ -29,6 +29,7 @@ import { SwipeNavigationProvider } from '@/contexts/SwipeNavigationContext' import { PermissionRequestDialog } from './components/session/PermissionRequestDialog' import { SSHHostKeyDialog } from './components/ssh/SSHHostKeyDialog' import { loginLoader, setupLoader, registerLoader, protectedLoader } from './lib/auth-loaders' +import { getSwipeBackTarget } from '@/lib/navigation' const queryClient = new QueryClient({ defaultOptions: { @@ -80,40 +81,20 @@ function AppShell() { const { open: openMobileSheet, openSheet } = useMobileTabBar() useTheme() - const getSwipeBackTarget = () => { - const path = location.pathname - if (path.match(/^\/repos\/[^/]+\/sessions\/[^/]+$/)) { - const repoId = path.split('/')[2] - return `/repos/${repoId}` - } - if (path.match(/^\/repos\/[^/]+$/)) { - return '/' - } - if (path.match(/^\/repos\/[^/]+\/memories$/)) { - const repoId = path.split('/')[2] - return `/repos/${repoId}` - } - if (path.match(/^\/repos\/[^/]+\/schedules$/)) { - const repoId = path.split('/')[2] - return `/repos/${repoId}` - } - if (path === '/schedules') { - return '/' - } - return null - } + const getRouteSwipeBackTarget = useCallback( + () => getSwipeBackTarget(location.pathname, location.search), + [location.pathname, location.search] + ) - const canSwipeBack = () => { - const path = location.pathname - return !['/login', '/setup', '/register', '/'].includes(path) && getSwipeBackTarget() !== null - } + const canSwipeBack = useCallback( + () => getRouteSwipeBackTarget() !== null, + [getRouteSwipeBackTarget] + ) - const handleSwipeBack = () => { - const target = getSwipeBackTarget() - if (target) { - navigate(target) - } - } + const handleSwipeBack = useCallback(() => { + const target = getRouteSwipeBackTarget() + if (target) navigate(target) + }, [getRouteSwipeBackTarget, navigate]) const { bind: bindRouteSwipe } = useSwipeBack( () => {}, diff --git a/frontend/src/components/message/VoiceStatusOverlay.tsx b/frontend/src/components/message/VoiceStatusOverlay.tsx index 8991f610..050cec20 100644 --- a/frontend/src/components/message/VoiceStatusOverlay.tsx +++ b/frontend/src/components/message/VoiceStatusOverlay.tsx @@ -14,6 +14,7 @@ export function VoiceStatusOverlay({ show, label, state }: VoiceStatusOverlayPro } const isLoading = state === 'starting' || state === 'processing' || state === 'sending' + const showLoadingText = state !== 'starting' const topLabel = state === 'readyToSend' ? 'Release' : state === 'starting' @@ -48,7 +49,9 @@ export function VoiceStatusOverlay({ show, label, state }: VoiceStatusOverlayPro {isLoading ? ( <> - {topLabel} + {showLoadingText && ( + {topLabel} + )} ) : ( <> @@ -61,11 +64,11 @@ export function VoiceStatusOverlay({ show, label, state }: VoiceStatusOverlayPro )} - {isLoading ? ( + {isLoading && showLoadingText ? ( {bottomLabel} - ) : ( + ) : !isLoading ? ( - )} + ) : null} ) diff --git a/frontend/src/components/settings/SettingsDialog.test.tsx b/frontend/src/components/settings/SettingsDialog.test.tsx new file mode 100644 index 00000000..a4aafc5b --- /dev/null +++ b/frontend/src/components/settings/SettingsDialog.test.tsx @@ -0,0 +1,118 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest' +import { render, screen, fireEvent } from '@testing-library/react' +import { MemoryRouter, useLocation, useNavigate } from 'react-router-dom' +import { SettingsDialog } from './SettingsDialog' + +vi.mock('@/components/settings/GeneralSettings', () => ({ + GeneralSettings: () =>
General Settings Content
, +})) + +vi.mock('@/components/settings/GitSettings', () => ({ + GitSettings: () =>
Git Settings Content
, +})) + +vi.mock('@/components/settings/KeyboardShortcuts', () => ({ + KeyboardShortcuts: () =>
Keyboard Shortcuts Content
, +})) + +vi.mock('@/components/settings/OpenCodeConfigManager', () => ({ + OpenCodeConfigManager: () =>
OpenCode Config Content
, +})) + +vi.mock('@/components/settings/ProviderSettings', () => ({ + ProviderSettings: () =>
Provider Settings Content
, +})) + +vi.mock('@/components/settings/AccountSettings', () => ({ + AccountSettings: () =>
Account Settings Content
, +})) + +vi.mock('@/components/settings/VoiceSettings', () => ({ + VoiceSettings: () =>
Voice Settings Content
, +})) + +vi.mock('@/components/settings/NotificationSettings', () => ({ + NotificationSettings: () =>
Notification Settings Content
, +})) + +vi.mock('@/hooks/useMobile', () => ({ + useSwipeBack: vi.fn(() => ({ + bind: vi.fn(), + swipeProgress: 0, + swipeStyles: {}, + })), +})) + +describe('SettingsDialog', () => { + beforeEach(() => { + vi.clearAllMocks() + }) + + it('resets to menu state when dialog closes and reopens', () => { + function TestWrapper() { + const location = useLocation() + const navigate = useNavigate() + + const searchParams = new URLSearchParams(location.search) + const isOpen = searchParams.get('settings') === 'open' + + return ( + <> + + + {isOpen && Dialog Open} + + + ) + } + + render( + + + + ) + + fireEvent.click(screen.getByText('Open Settings')) + expect(screen.getByTestId('dialog-open')).toBeInTheDocument() + + fireEvent.click(screen.getByText('Close Settings')) + expect(screen.queryByTestId('dialog-open')).not.toBeInTheDocument() + + fireEvent.click(screen.getByText('Open Settings')) + expect(screen.getByTestId('dialog-open')).toBeInTheDocument() + }) + + it('displays menu items in mobile view', () => { + function TestWrapper() { + const location = useLocation() + const navigate = useNavigate() + + const searchParams = new URLSearchParams(location.search) + const isOpen = searchParams.get('settings') === 'open' + + return ( + <> + + {isOpen && Dialog Open} + + + ) + } + + render( + + + + ) + + fireEvent.click(screen.getByText('Open Settings')) + expect(screen.getByTestId('dialog-open')).toBeInTheDocument() + + expect(screen.getAllByText('Account').length).toBeGreaterThanOrEqual(1) + expect(screen.getAllByText('General').length).toBeGreaterThanOrEqual(1) + expect(screen.getAllByText('Git').length).toBeGreaterThanOrEqual(1) + expect(screen.getAllByText('Shortcuts').length).toBeGreaterThanOrEqual(1) + expect(screen.getAllByText('OpenCode').length).toBeGreaterThanOrEqual(1) + expect(screen.getAllByText('Providers').length).toBeGreaterThanOrEqual(1) + }) +}) diff --git a/frontend/src/components/settings/SettingsDialog.tsx b/frontend/src/components/settings/SettingsDialog.tsx index 9217c3a4..ea4fa499 100644 --- a/frontend/src/components/settings/SettingsDialog.tsx +++ b/frontend/src/components/settings/SettingsDialog.tsx @@ -1,4 +1,4 @@ -import { useState, useRef, useEffect } from 'react' +import { useState, useRef, useEffect, useCallback } from 'react' import { GeneralSettings } from '@/components/settings/GeneralSettings' import { GitSettings } from '@/components/settings/GitSettings' import { KeyboardShortcuts } from '@/components/settings/KeyboardShortcuts' @@ -19,12 +19,44 @@ type SettingsView = 'menu' | 'general' | 'git' | 'shortcuts' | 'opencode' | 'pro export function SettingsDialog() { const { isOpen, close, activeTab, setActiveTab } = useSettingsDialog() const [mobileView, setMobileView] = useState('menu') + const [sectionHistory, setSectionHistory] = useState([]) const contentRef = useRef(null) + const pushSectionHistory = useCallback((view: SettingsView) => { + if (view === 'menu') return + setSectionHistory((history) => { + if (history.at(-1) === view) return history + return [...history, view] + }) + }, []) + + const handleSettingsBack = useCallback(() => { + if (mobileView === 'menu') { + close() + return + } + + const currentIndex = sectionHistory.lastIndexOf(mobileView) + const previousHistory = currentIndex >= 0 + ? sectionHistory.slice(0, currentIndex) + : sectionHistory + const previousView = previousHistory.at(-1) + + if (previousView) { + setSectionHistory(previousHistory) + setMobileView(previousView) + setActiveTab(previousView) + return + } + + setSectionHistory([]) + setMobileView('menu') + }, [mobileView, sectionHistory, close, setActiveTab]) + const { bind: bindSwipe, swipeStyles } = useSwipeBack(close, { enabled: isOpen, canBack: () => mobileView !== 'menu', - onBack: () => setMobileView('menu'), + onBack: handleSettingsBack, }) useEffect(() => { @@ -32,7 +64,11 @@ export function SettingsDialog() { }, [bindSwipe]) useEffect(() => { - if (!isOpen) return + if (!isOpen) { + setMobileView('menu') + setSectionHistory([]) + return + } const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') { e.stopPropagation() @@ -54,8 +90,17 @@ export function SettingsDialog() { { id: 'providers', icon: Key, label: 'Providers', description: 'Manage AI provider API keys' }, ] + const handleOpenMobileView = useCallback((view: SettingsView) => { + setMobileView(view) + setActiveTab(view) + pushSectionHistory(view) + }, [setActiveTab, pushSectionHistory]) + const handleTabChange = (tab: string) => { - setActiveTab(tab as SettingsView) + const nextView = tab as SettingsView + setActiveTab(nextView) + setMobileView(nextView) + pushSectionHistory(nextView) } return ( @@ -128,16 +173,16 @@ export function SettingsDialog() {
- {mobileView !== 'menu' && ( - - )} + {mobileView !== 'menu' && ( + + )}

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

@@ -156,14 +201,11 @@ export function SettingsDialog() { {mobileView === 'menu' && (
{menuItems.map((item) => ( -