The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 25, 11:00 UTC
Show branch toolbar for local draft threads
Co-authored-by: codex <codex@users.noreply.github.com>
Julius Marminge committed
Mar 1, 2026 at 21:35 UTC
69a4fa82155f05637f73b3d2f61a5cdf9366b4b9
1 file changed
+48
-19
apps/web/src/components/BranchToolbar.tsx
+48
-19
@@ -9,6 +9,7 @@ import {
9
gitCreateBranchAndCheckoutMutationOptions,
10
} from "../lib/gitReactQuery";
11
import { readNativeApi } from "../nativeApi";
12
+import { useComposerDraftStore } from "../composerDraftStore";
13
import { useStore } from "../store";
14
import {
15
dedupeRemoteBranchesWithLocalMatches,
@@ -43,17 +44,21 @@ export default function BranchToolbar({
44
onComposerFocusRequest,
45
}: BranchToolbarProps) {
46
const { state, dispatch } = useStore();
47
+ const draftThread = useComposerDraftStore((store) => store.getDraftThread(threadId));
48
+ const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext);
49
const queryClient = useQueryClient();
50
51
const [isBranchMenuOpen, setIsBranchMenuOpen] = useState(false);
52
const [branchQuery, setBranchQuery] = useState("");
53
51
- const activeThread = state.threads.find((thread) => thread.id === threadId);
52
- const activeProject = state.projects.find((project) => project.id === activeThread?.projectId);
53
- const activeThreadId = activeThread?.id;
54
- const activeThreadBranch = activeThread?.branch ?? null;
55
- const activeWorktreePath = activeThread?.worktreePath ?? null;
54
+ const serverThread = state.threads.find((thread) => thread.id === threadId);
55
+ const activeProjectId = serverThread?.projectId ?? draftThread?.projectId ?? null;
56
+ const activeProject = state.projects.find((project) => project.id === activeProjectId);
57
+ const activeThreadId = serverThread?.id ?? (draftThread ? threadId : undefined);
58
+ const activeThreadBranch = serverThread?.branch ?? draftThread?.branch ?? null;
59
+ const activeWorktreePath = serverThread?.worktreePath ?? draftThread?.worktreePath ?? null;
60
const branchCwd = activeWorktreePath ?? activeProject?.cwd ?? null;
61
+ const hasServerThread = serverThread !== undefined;
62
63
// ── Queries ───────────────────────────────────────────────────────────
64
@@ -95,7 +100,7 @@ export default function BranchToolbar({
100
if (!activeThreadId || !syncedBranch) return;
101
const api = readNativeApi();
102
98
- if (api) {
103
+ if (api && hasServerThread) {
104
void api.orchestration.dispatchCommand({
105
type: "thread.meta.update",
106
commandId: newCommandId(),
@@ -104,13 +109,30 @@ export default function BranchToolbar({
109
worktreePath: null,
110
});
111
}
107
- dispatch({
108
- type: "SET_THREAD_BRANCH",
109
- threadId: activeThreadId,
112
+ if (hasServerThread) {
113
+ dispatch({
114
+ type: "SET_THREAD_BRANCH",
115
+ threadId: activeThreadId,
116
+ branch: syncedBranch,
117
+ worktreePath: null,
118
+ });
119
+ return;
120
+ }
121
+ setDraftThreadContext(threadId, {
122
branch: syncedBranch,
123
worktreePath: null,
124
});
113
- }, [activeThreadId, activeWorktreePath, activeThreadBranch, queryBranches, envMode, dispatch]);
125
+ }, [
126
+ activeThreadId,
127
+ activeWorktreePath,
128
+ activeThreadBranch,
129
+ queryBranches,
130
+ envMode,
131
+ dispatch,
132
+ hasServerThread,
133
+ setDraftThreadContext,
134
+ threadId,
135
+ ]);
136
137
useEffect(() => {
138
if (isBranchMenuOpen) return;
@@ -129,7 +151,7 @@ export default function BranchToolbar({
151
const api = readNativeApi();
152
// If the effective cwd is about to change, stop the running session so the
153
// next message creates a new one with the correct cwd.
132
- const sessionId = activeThread?.session?.sessionId;
154
+ const sessionId = serverThread?.session?.sessionId;
155
if (sessionId && worktreePath !== activeWorktreePath && api) {
156
void api.orchestration
157
.dispatchCommand({
@@ -140,7 +162,7 @@ export default function BranchToolbar({
162
})
163
.catch(() => undefined);
164
}
143
- if (api) {
165
+ if (api && hasServerThread) {
166
void api.orchestration.dispatchCommand({
167
type: "thread.meta.update",
168
commandId: newCommandId(),
@@ -149,7 +171,14 @@ export default function BranchToolbar({
171
worktreePath,
172
});
173
}
152
- dispatch({ type: "SET_THREAD_BRANCH", threadId: activeThreadId, branch, worktreePath });
174
+ if (hasServerThread) {
175
+ dispatch({ type: "SET_THREAD_BRANCH", threadId: activeThreadId, branch, worktreePath });
176
+ return;
177
+ }
178
+ setDraftThreadContext(threadId, {
179
+ branch,
180
+ worktreePath,
181
+ });
182
};
183
184
const selectBranch = (branch: GitBranch) => {
@@ -221,7 +250,7 @@ export default function BranchToolbar({
250
});
251
};
252
224
- if (!activeThread || !activeProject) return null;
253
+ if (!activeThreadId || !activeProject) return null;
254
255
return (
256
<div className="mx-auto flex w-full max-w-3xl items-center justify-between px-5 pb-3 pt-1">
@@ -248,7 +277,7 @@ export default function BranchToolbar({
277
autoHighlight
278
onOpenChange={(open) => setIsBranchMenuOpen(open)}
279
open={isBranchMenuOpen}
251
- value={activeThread.branch}
280
+ value={activeThreadBranch}
281
>
282
<ComboboxTrigger
283
render={<Button variant="ghost" size="xs" />}
@@ -256,10 +285,10 @@ export default function BranchToolbar({
285
disabled={branchesQuery.isLoading}
286
>
287
<span className="max-w-[240px] truncate">
259
- {activeThread.branch
288
+ {activeThreadBranch
289
? envMode === "worktree" && !activeWorktreePath
261
- ? `From ${activeThread.branch}`
262
- : activeThread.branch
290
+ ? `From ${activeThreadBranch}`
291
+ : activeThreadBranch
292
: "Select branch"}
293
</span>
294
<ChevronDownIcon />
@@ -313,7 +342,7 @@ export default function BranchToolbar({
342
key={itemValue}
343
value={itemValue}
344
className={
316
- itemValue === activeThread.branch ? "bg-accent text-foreground" : undefined
345
+ itemValue === activeThreadBranch ? "bg-accent text-foreground" : undefined
346
}
347
onClick={() => selectBranch(branch)}
348
>