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
2 2
3export type EnvMode = "local" | "worktree";3export type EnvMode = "local" | "worktree";
4 4
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"; · 4 unmodified lines
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";
11 15
@@ -38,10 +42,11 @@ export default function BranchToolbar({ · 26 unmodified lines
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 });
45 50
46 const setThreadBranch = useCallback(51 const setThreadBranch = useCallback(
47 (branch: string | null, worktreePath: string | null) => {52 (branch: string | null, worktreePath: string | null) => {