Files
opencode-manager/frontend/src/lib/navigation.ts
T
Chris Scott e959cc409f 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
2026-04-29 22:49:23 -04:00

53 lines
1.5 KiB
TypeScript

export function getSessionListPath(repoId: string | number, isAssistantSession: boolean): string {
const id = String(repoId);
if (isAssistantSession) {
return `/repos/${id}/assistant?view=sessions`;
}
return `/repos/${id}`;
}
export function getSwipeBackTarget(pathname: string, search = ''): string | null {
const sessionDetailRegex = /^\/repos\/([^/]+)\/sessions\/[^/]+$/;
const match = pathname.match(sessionDetailRegex);
if (match) {
const repoId = match[1];
const params = new URLSearchParams(search);
const isAssistant = params.get('assistant') === '1';
return getSessionListPath(repoId, isAssistant);
}
if (pathname === '/repos/:id/assistant' || /^\/repos\/[^/]+\/assistant$/.test(pathname)) {
const repoId = pathname.split('/')[2];
const params = new URLSearchParams(search);
if (params.get('view') !== 'sessions') {
return getSessionListPath(repoId, true);
}
return `/repos/${repoId}`;
}
if (/^\/repos\/[^/]+$/.test(pathname)) {
return '/';
}
if (/^\/repos\/[^/]+\/memories$/.test(pathname)) {
const repoId = pathname.split('/')[2];
return `/repos/${repoId}`;
}
if (/^\/repos\/[^/]+\/schedules$/.test(pathname)) {
const repoId = pathname.split('/')[2];
return `/repos/${repoId}`;
}
if (pathname === '/schedules') {
return '/';
}
if (pathname === '/' || pathname === '/login' || pathname === '/setup' || pathname === '/register') {
return null;
}
return null;
}