Skip to content

Commit 4598363

Browse files
authored
fix: QOL changes for task input (#249)
1 parent 87b9b11 commit 4598363

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

apps/array/src/renderer/features/task-detail/components/BranchSelect.tsx

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,28 @@ import { ChevronDownIcon } from "@radix-ui/react-icons";
33
import { Button, DropdownMenu, Flex, Text, TextField } from "@radix-ui/themes";
44
import type { Responsive } from "@radix-ui/themes/dist/esm/props/prop-def.js";
55
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
6+
import type { RunMode } from "./RunModeSelect";
67

78
const MAX_DISPLAYED_BRANCHES = 20;
89

910
interface BranchSelectProps {
1011
value: string | null; // null means use default branch
1112
onChange: (branch: string | null) => void;
1213
directoryPath: string;
14+
runMode: RunMode;
1315
size?: Responsive<"1" | "2">;
1416
}
1517

1618
export function BranchSelect({
1719
value,
1820
onChange,
1921
directoryPath,
22+
runMode,
2023
size = "1",
2124
}: BranchSelectProps) {
2225
const [branches, setBranches] = useState<string[]>([]);
2326
const [defaultBranch, setDefaultBranch] = useState<string>("");
27+
const [currentBranch, setCurrentBranch] = useState<string>("");
2428
const [isCreatingNew, setIsCreatingNew] = useState(false);
2529
const [newBranchName, setNewBranchName] = useState("");
2630
const [searchQuery, setSearchQuery] = useState("");
@@ -32,6 +36,7 @@ export function BranchSelect({
3236
setIsLoading(false);
3337
setBranches([]);
3438
setDefaultBranch("");
39+
setCurrentBranch("");
3540
return;
3641
}
3742

@@ -41,15 +46,18 @@ export function BranchSelect({
4146
const load = async () => {
4247
setIsLoading(true);
4348
try {
44-
const [allBranches, detectedDefault] = await Promise.all([
45-
window.electronAPI.getAllBranches(directoryPath),
46-
window.electronAPI.getDefaultBranch(directoryPath),
47-
]);
49+
const [allBranches, detectedDefault, detectedCurrent] =
50+
await Promise.all([
51+
window.electronAPI.getAllBranches(directoryPath),
52+
window.electronAPI.getDefaultBranch(directoryPath),
53+
window.electronAPI.getCurrentBranch(directoryPath),
54+
]);
4855

4956
if (cancelled) return;
5057

5158
setBranches(allBranches);
5259
setDefaultBranch(detectedDefault);
60+
setCurrentBranch(detectedCurrent ?? "");
5361
} catch (_error) {
5462
} finally {
5563
if (!cancelled) {
@@ -65,25 +73,39 @@ export function BranchSelect({
6573
};
6674
}, [directoryPath]);
6775

76+
// Determine which branch to use as the initial value based on run mode
77+
const initialBranch =
78+
runMode === "local" ? currentBranch || defaultBranch : defaultBranch;
79+
6880
useEffect(() => {
69-
if (!hasSetInitialValue.current && value === null && defaultBranch) {
81+
if (!hasSetInitialValue.current && value === null && initialBranch) {
7082
hasSetInitialValue.current = true;
71-
onChange(defaultBranch);
83+
onChange(initialBranch);
84+
}
85+
}, [initialBranch, value, onChange]);
86+
87+
// Reset branch selection when runMode changes
88+
useEffect(() => {
89+
if (initialBranch) {
90+
onChange(initialBranch);
7291
}
73-
}, [defaultBranch, value, onChange]);
92+
}, [initialBranch, onChange]); // eslint-disable-line react-hooks/exhaustive-deps
7493

7594
const handleOpenChange = useCallback(
7695
async (open: boolean) => {
7796
if (open) {
7897
setSearchQuery("");
7998
if (directoryPath) {
8099
try {
81-
const [allBranches, detectedDefault] = await Promise.all([
82-
window.electronAPI.getAllBranches(directoryPath),
83-
window.electronAPI.getDefaultBranch(directoryPath),
84-
]);
100+
const [allBranches, detectedDefault, detectedCurrent] =
101+
await Promise.all([
102+
window.electronAPI.getAllBranches(directoryPath),
103+
window.electronAPI.getDefaultBranch(directoryPath),
104+
window.electronAPI.getCurrentBranch(directoryPath),
105+
]);
85106
setBranches(allBranches);
86107
setDefaultBranch(detectedDefault);
108+
setCurrentBranch(detectedCurrent ?? "");
87109
} catch (_error) {}
88110
}
89111
}

apps/array/src/renderer/features/task-detail/components/TaskInput.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ export function TaskInput() {
148148
value={selectedBranch}
149149
onChange={setSelectedBranch}
150150
directoryPath={selectedDirectory}
151+
runMode={runMode}
151152
/>
152153
)}
153154
</Flex>

apps/array/src/renderer/features/task-detail/components/TaskInputEditor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ModelSelector } from "@features/sessions/components/ModelSelector";
12
import { ArrowUpIcon, GitBranchIcon, Paperclip } from "@phosphor-icons/react";
23
import { Box, Flex, IconButton, Text, Tooltip } from "@radix-ui/themes";
34
import type { Editor } from "@tiptap/react";
@@ -139,7 +140,7 @@ export function TaskInputEditor({
139140
</Flex>
140141

141142
<Flex justify="between" align="center" px="3" pb="3">
142-
<Flex align="center">
143+
<Flex align="center" gap="1">
143144
<input
144145
ref={fileInputRef}
145146
type="file"
@@ -161,6 +162,7 @@ export function TaskInputEditor({
161162
<Paperclip size={16} weight="bold" />
162163
</IconButton>
163164
</Tooltip>
165+
<ModelSelector disabled={isCreatingTask} />
164166
</Flex>
165167

166168
<Flex align="center" gap="4">

0 commit comments

Comments
 (0)