From 93af851dc53e950673dacc1fb79c2bd95a8b6a9d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 3 Mar 2026 09:55:52 -0800 Subject: [PATCH] type --- .../web/src/components/BranchToolbar.logic.ts | 8 ++++--- apps/web/src/components/BranchToolbar.tsx | 8 +++---- .../BranchToolbarBranchSelector.tsx | 22 +++++++++++++++---- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/apps/web/src/components/BranchToolbar.logic.ts b/apps/web/src/components/BranchToolbar.logic.ts index dd1912fb2493eb9377d2dd8c4f414dc22ba76746..855b39bbbc337ea06c6406734c888f04b1f9dbdc 100644 --- a/apps/web/src/components/BranchToolbar.logic.ts +++ b/apps/web/src/components/BranchToolbar.logic.ts @@ -1,10 +1,12 @@ import type { GitBranch } from "@t3tools/contracts"; +export type EnvMode = "local" | "worktree"; + export function resolveDraftEnvModeAfterBranchChange(input: { nextWorktreePath: string | null; currentWorktreePath: string | null; - effectiveEnvMode: "local" | "worktree"; -}): "local" | "worktree" { + effectiveEnvMode: EnvMode; +}): EnvMode { const { nextWorktreePath, currentWorktreePath, effectiveEnvMode } = input; if (nextWorktreePath) { return "worktree"; @@ -16,7 +18,7 @@ export function resolveDraftEnvModeAfterBranchChange(input: { } export function resolveBranchToolbarValue(input: { - envMode: "local" | "worktree"; + envMode: EnvMode; activeWorktreePath: string | null; activeThreadBranch: string | null; currentGitBranch: string | null; diff --git a/apps/web/src/components/BranchToolbar.tsx b/apps/web/src/components/BranchToolbar.tsx index 9d208a32c8494dfa5f0128a7b04da118d412a973..d4c0b4a59a98dc86ab8c6a7385f261391768748b 100644 --- a/apps/web/src/components/BranchToolbar.tsx +++ b/apps/web/src/components/BranchToolbar.tsx @@ -5,14 +5,14 @@ import { newCommandId } from "../lib/utils"; import { readNativeApi } from "../nativeApi"; import { useComposerDraftStore } from "../composerDraftStore"; import { useStore } from "../store"; -import { resolveDraftEnvModeAfterBranchChange } from "./BranchToolbar.logic"; +import { EnvMode, resolveDraftEnvModeAfterBranchChange } from "./BranchToolbar.logic"; import { BranchToolbarBranchSelector } from "./BranchToolbarBranchSelector"; import { Button } from "./ui/button"; interface BranchToolbarProps { threadId: ThreadId; - envMode: "local" | "worktree"; - onEnvModeChange: (mode: "local" | "worktree") => void; + envMode: EnvMode; + onEnvModeChange: (mode: EnvMode) => void; envLocked: boolean; onComposerFocusRequest?: () => void; } @@ -38,7 +38,7 @@ export default function BranchToolbar({ const activeWorktreePath = serverThread?.worktreePath ?? draftThread?.worktreePath ?? null; const branchCwd = activeWorktreePath ?? activeProject?.cwd ?? null; const hasServerThread = serverThread !== undefined; - const effectiveEnvMode: "local" | "worktree" = + const effectiveEnvMode: EnvMode = activeWorktreePath || (!hasServerThread && draftThread?.envMode === "worktree") ? "worktree" : envMode; diff --git a/apps/web/src/components/BranchToolbarBranchSelector.tsx b/apps/web/src/components/BranchToolbarBranchSelector.tsx index bb3170981f22f6c9ab26a0ea0edbc6e7a438d454..ba27e383d8c834912cd2e2ec813b76908aef0ef7 100644 --- a/apps/web/src/components/BranchToolbarBranchSelector.tsx +++ b/apps/web/src/components/BranchToolbarBranchSelector.tsx @@ -2,13 +2,22 @@ import type { GitBranch } from "@t3tools/contracts"; import { useQuery, useQueryClient } from "@tanstack/react-query"; import { useVirtualizer } from "@tanstack/react-virtual"; import { ChevronDownIcon } from "lucide-react"; -import { useCallback, useEffect, useMemo, useOptimistic, useRef, useState, useTransition } from "react"; +import { + useCallback, + useEffect, + useMemo, + useOptimistic, + useRef, + useState, + useTransition, +} from "react"; import { gitBranchesQueryOptions, gitQueryKeys, invalidateGitQueries } from "../lib/gitReactQuery"; import { readNativeApi } from "../nativeApi"; import { dedupeRemoteBranchesWithLocalMatches, deriveLocalBranchNameFromRemoteRef, + EnvMode, resolveBranchToolbarValue, } from "./BranchToolbar.logic"; import { Button } from "./ui/button"; @@ -28,7 +37,7 @@ interface BranchToolbarBranchSelectorProps { activeThreadBranch: string | null; activeWorktreePath: string | null; branchCwd: string | null; - effectiveEnvMode: "local" | "worktree"; + effectiveEnvMode: EnvMode; envLocked: boolean; onSetThreadBranch: (branch: string | null, worktreePath: string | null) => void; onComposerFocusRequest?: () => void; @@ -40,7 +49,7 @@ function toBranchActionErrorMessage(error: unknown): string { function getBranchTriggerLabel(input: { activeWorktreePath: string | null; - effectiveEnvMode: "local" | "worktree"; + effectiveEnvMode: EnvMode; resolvedActiveBranch: string | null; }): string { const { activeWorktreePath, effectiveEnvMode, resolvedActiveBranch } = input; @@ -215,7 +224,12 @@ export function BranchToolbarBranchSelector({ }; useEffect(() => { - if (effectiveEnvMode !== "worktree" || activeWorktreePath || activeThreadBranch || !currentGitBranch) { + if ( + effectiveEnvMode !== "worktree" || + activeWorktreePath || + activeThreadBranch || + !currentGitBranch + ) { return; } onSetThreadBranch(currentGitBranch, null); -- 2.54.0