History

helper

Julius Marminge committed 8 months ago

Commit 760fe641 parent 93af8512 files · +21 −5Browse files

Unified · Split

2 files
  1. apps/web/src/components/BranchToolbar.logic.ts +11 −0
  2. apps/web/src/components/BranchToolbar.tsx +10 −5
apps/web/src/components/BranchToolbar.logic.ts+11−0
@@ -2,6 +2,17 @@ import type { GitBranch } from "@t3tools/contracts"; · 1 unmodified line
22
33 export type EnvMode = "local" | "worktree";
44
5+export 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+
516 export function resolveDraftEnvModeAfterBranchChange(input: {
617 nextWorktreePath: string | null;
718 currentWorktreePath: string | null;
apps/web/src/components/BranchToolbar.tsx+10−5
@@ -5,7 +5,11 @@ import { newCommandId } from "../lib/utils"; · 4 unmodified lines
55 import { readNativeApi } from "../nativeApi";
66 import { useComposerDraftStore } from "../composerDraftStore";
77 import { useStore } from "../store";
8−import { EnvMode, resolveDraftEnvModeAfterBranchChange } from "./BranchToolbar.logic";
8+import {
9+ EnvMode,
10+ resolveDraftEnvModeAfterBranchChange,
11+ resolveEffectiveEnvMode,
12+} from "./BranchToolbar.logic";
913 import { BranchToolbarBranchSelector } from "./BranchToolbarBranchSelector";
1014 import { Button } from "./ui/button";
1115
@@ -38,10 +42,11 @@ export default function BranchToolbar({ · 26 unmodified lines
3842 const activeWorktreePath = serverThread?.worktreePath ?? draftThread?.worktreePath ?? null;
3943 const branchCwd = activeWorktreePath ?? activeProject?.cwd ?? null;
4044 const hasServerThread = serverThread !== undefined;
41− const effectiveEnvMode: EnvMode =
42− activeWorktreePath || (!hasServerThread && draftThread?.envMode === "worktree")
43− ? "worktree"
44− : envMode;
45+ const effectiveEnvMode = resolveEffectiveEnvMode({
46+ activeWorktreePath,
47+ hasServerThread,
48+ draftThreadEnvMode: draftThread?.envMode,
49+ });
4550
4651 const setThreadBranch = useCallback(
4752 (branch: string | null, worktreePath: string | null) => {