refactor(frontend): extract navigation helpers and improve settings back navigation (#210)

* feat: add persistent model state storage with database backend

- Create opencode_model_state table for storing user model preferences
- Implement database-backed model state management (recent, favorite, variant)
- Add atomic JSON file utilities with file locking for concurrent safety
- Migrate providers routes from file-based to database storage
- Add backfill migration to preserve existing model.json data
- Include comprehensive tests for model-state and atomic-json modules
- Refactor useSessionAgent hook to simplify agent/model resolution logic
- Update getFileApiUrl to use consistent query parameter approach

* fix: include workspace dependencies in Docker image

* fix: overlay workspace node_modules after source to prevent layer overwrite

* fix: ensure model state table exists for existing databases

* feat: add model state persistence and improve model selection sync

- Add setActiveModel to modelStore and useModelSelection for direct model updates
- Sync session agent model/variant to store when messages load
- Include model, agent, and variant in optimistic user messages
- Fix useSessionAgent to check isFetching during message loading
- Update env.ts to use getter for BASE_PATH for dynamic resolution
- Fix test environment variable from OPENCODE_WORKSPACE_PATH to WORKSPACE_PATH

* refactor(frontend): extract navigation helpers and improve settings back navigation

- Move swipe-back route logic into shared navigation.ts module
- Add getSessionListPath helper for consistent session list navigation
- Add section history tracking to settings dialog for proper back navigation
- Fix voice status overlay loading text visibility during starting state
- Update env and vite config for production domain
This commit is contained in:
Chris Scott authored and GitHub committed 2026-04-29 22:49:23 -04:00
1 parent 549e0ac7b2
commit e959cc409f
10 files changed
+361 -66

No files matched your search

+14 -33
View File
@@ -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(
() => {},