authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-03-03 09:57:17-08:00
committergravatar for jmarminge@gmail.comJulius Marminge <jmarminge@gmail.com> 2026-03-03 10:01:18-08:00
log760fe643e857d5b5f9fcd1cb4ceb9fe55df988fc
tree3dd410110f65a66d8dd1212b4f91d9461f42c5ec
parent93af851dc53e950673dacc1fb79c2bd95a8b6a9d

helper


2 files changed, 21 insertions(+), 5 deletions(-)

apps/web/src/components/BranchToolbar.logic.ts+11
...@@ -2,6 +2,17 @@ import type { GitBranch } from "@t3tools/contracts";...@@ -2,6 +2,17 @@ import type { GitBranch } from "@t3tools/contracts";
22
3export type EnvMode = "local" | "worktree";3export type EnvMode = "local" | "worktree";
44
5export function resolveEffectiveEnvMode(input: {
6 activeWorktreePath: string | null;
7 hasServerThread: boolean;
8 draftThreadEnvMode: EnvMode | undefined;
9}): EnvMode {
10 const { activeWorktreePath, hasServerThread, draftThreadEnvMode } = input;
11 return activeWorktreePath || (!hasServerThread && draftThreadEnvMode === "worktree")
12 ? "worktree"
13 : "local";
14}
15
5export function resolveDraftEnvModeAfterBranchChange(input: {16export function resolveDraftEnvModeAfterBranchChange(input: {
6 nextWorktreePath: string | null;17 nextWorktreePath: string | null;
7 currentWorktreePath: string | null;18 currentWorktreePath: string | null;
apps/web/src/components/BranchToolbar.tsx+10-5
...@@ -5,7 +5,11 @@ import { newCommandId } from "../lib/utils";...@@ -5,7 +5,11 @@ import { newCommandId } from "../lib/utils";
5import { readNativeApi } from "../nativeApi";5import { readNativeApi } from "../nativeApi";
6import { useComposerDraftStore } from "../composerDraftStore";6import { useComposerDraftStore } from "../composerDraftStore";
7import { useStore } from "../store";7import { useStore } from "../store";
8import { EnvMode, resolveDraftEnvModeAfterBranchChange } from "./BranchToolbar.logic";8import {
9 EnvMode,
10 resolveDraftEnvModeAfterBranchChange,
11 resolveEffectiveEnvMode,
12} from "./BranchToolbar.logic";
9import { BranchToolbarBranchSelector } from "./BranchToolbarBranchSelector";13import { BranchToolbarBranchSelector } from "./BranchToolbarBranchSelector";
10import { Button } from "./ui/button";14import { Button } from "./ui/button";
1115
...@@ -38,10 +42,11 @@ export default function BranchToolbar({...@@ -38,10 +42,11 @@ export default function BranchToolbar({
38 const activeWorktreePath = serverThread?.worktreePath ?? draftThread?.worktreePath ?? null;42 const activeWorktreePath = serverThread?.worktreePath ?? draftThread?.worktreePath ?? null;
39 const branchCwd = activeWorktreePath ?? activeProject?.cwd ?? null;43 const branchCwd = activeWorktreePath ?? activeProject?.cwd ?? null;
40 const hasServerThread = serverThread !== undefined;44 const hasServerThread = serverThread !== undefined;
41 const effectiveEnvMode: EnvMode =45 const effectiveEnvMode = resolveEffectiveEnvMode({
42 activeWorktreePath || (!hasServerThread && draftThread?.envMode === "worktree")46 activeWorktreePath,
43 ? "worktree"47 hasServerThread,
44 : envMode;48 draftThreadEnvMode: draftThread?.envMode,
49 });
4550
46 const setThreadBranch = useCallback(51 const setThreadBranch = useCallback(
47 (branch: string | null, worktreePath: string | null) => {52 (branch: string | null, worktreePath: string | null) => {