|
1 | 1 | import { useState, useEffect, useCallback } from "react"; |
2 | 2 | import type { FrontendWorkspaceMetadata } from "@/common/types/workspace"; |
3 | 3 | import type { RuntimeConfig, RuntimeMode } from "@/common/types/runtime"; |
| 4 | +import type { UIMode } from "@/common/types/mode"; |
| 5 | +import type { ThinkingLevel } from "@/common/types/thinking"; |
4 | 6 | import { parseRuntimeString } from "@/browser/utils/chatCommands"; |
5 | 7 | import { useDraftWorkspaceSettings } from "@/browser/hooks/useDraftWorkspaceSettings"; |
| 8 | +import { readPersistedState, updatePersistedState } from "@/browser/hooks/usePersistedState"; |
6 | 9 | import { useSendMessageOptions } from "@/browser/hooks/useSendMessageOptions"; |
7 | | -import { getProjectScopeId } from "@/common/constants/storage"; |
| 10 | +import { getModeKey, getProjectScopeId, getThinkingLevelKey } from "@/common/constants/storage"; |
8 | 11 | import { extractErrorMessage } from "./utils"; |
9 | 12 |
|
10 | 13 | interface UseCreationWorkspaceOptions { |
11 | 14 | projectPath: string; |
12 | 15 | onWorkspaceCreated: (metadata: FrontendWorkspaceMetadata) => void; |
13 | 16 | } |
14 | 17 |
|
| 18 | +function syncCreationPreferences(projectPath: string, workspaceId: string): void { |
| 19 | + const projectScopeId = getProjectScopeId(projectPath); |
| 20 | + |
| 21 | + const projectMode = readPersistedState<UIMode | null>(getModeKey(projectScopeId), null); |
| 22 | + if (projectMode) { |
| 23 | + updatePersistedState(getModeKey(workspaceId), projectMode); |
| 24 | + } |
| 25 | + |
| 26 | + const projectThinking = readPersistedState<ThinkingLevel | null>( |
| 27 | + getThinkingLevelKey(projectScopeId), |
| 28 | + null |
| 29 | + ); |
| 30 | + if (projectThinking) { |
| 31 | + updatePersistedState(getThinkingLevelKey(workspaceId), projectThinking); |
| 32 | + } |
| 33 | +} |
| 34 | + |
15 | 35 | interface UseCreationWorkspaceReturn { |
16 | 36 | branches: string[]; |
17 | 37 | trunkBranch: string; |
@@ -97,6 +117,7 @@ export function useCreationWorkspace({ |
97 | 117 |
|
98 | 118 | // Check if this is a workspace creation result (has metadata field) |
99 | 119 | if ("metadata" in result && result.metadata) { |
| 120 | + syncCreationPreferences(projectPath, result.metadata.id); |
100 | 121 | // Settings are already persisted via useDraftWorkspaceSettings |
101 | 122 | // Notify parent to switch workspace (clears input via parent unmount) |
102 | 123 | onWorkspaceCreated(result.metadata); |
|
0 commit comments