Skip to content

Commit 2fa1d4f

Browse files
committed
🤖 Remove unnecessary enabled parameter from useNewWorkspaceOptions
The enabled parameter was over-engineering: - localStorage reads are synchronous and cheap - projectPath already handles null/undefined case - Loading prefs when modal is closed doesn't hurt anything - Simpler hooks are better - removed unnecessary conditional logic Hook now only depends on projectPath, making it more predictable.
1 parent 9ac514b commit 2fa1d4f

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/components/NewWorkspaceModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const NewWorkspaceModal: React.FC<NewWorkspaceModalProps> = ({
3838
const hasBranches = branches.length > 0;
3939

4040
// Load runtime preferences from localStorage for this project
41-
const [runtimeOptions, setRuntimeOptions] = useNewWorkspaceOptions(projectPath, isOpen);
41+
const [runtimeOptions, setRuntimeOptions] = useNewWorkspaceOptions(projectPath);
4242
const { runtimeMode, sshHost, getRuntimeString } = runtimeOptions;
4343

4444
useEffect(() => {

src/hooks/useNewWorkspaceOptions.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,18 @@ export interface WorkspaceRuntimeOptions {
2121
* Loads saved runtime preference for a project and provides consistent state management.
2222
*
2323
* @param projectPath - Path to the project (used as key for localStorage)
24-
* @param enabled - Whether to load saved preferences (default: true)
2524
* @returns Runtime options state and setter
2625
*/
2726
export function useNewWorkspaceOptions(
28-
projectPath: string | null | undefined,
29-
enabled = true
27+
projectPath: string | null | undefined
3028
): [WorkspaceRuntimeOptions, (mode: RuntimeMode, host?: string) => void] {
3129
const [runtimeMode, setRuntimeMode] = useState<RuntimeMode>(RUNTIME_MODE.LOCAL);
3230
const [sshHost, setSshHost] = useState("");
3331

3432
// Load saved runtime preference when projectPath changes
3533
useEffect(() => {
36-
if (!enabled || !projectPath) {
37-
// Reset to defaults when disabled or no project
34+
if (!projectPath) {
35+
// Reset to defaults when no project
3836
setRuntimeMode(RUNTIME_MODE.LOCAL);
3937
setSshHost("");
4038
return;
@@ -46,7 +44,7 @@ export function useNewWorkspaceOptions(
4644

4745
setRuntimeMode(parsed.mode);
4846
setSshHost(parsed.host);
49-
}, [projectPath, enabled]);
47+
}, [projectPath]);
5048

5149
// Setter for updating both mode and host
5250
const setRuntimeOptions = (mode: RuntimeMode, host?: string) => {

0 commit comments

Comments
 (0)