Skip to content

Commit e4f0c37

Browse files
committed
fix(web): settle shortcuts now match the active thread state
1 parent 5d19de1 commit e4f0c37

2 files changed

Lines changed: 32 additions & 56 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ import {
204204
} from "../hooks/useSettings";
205205
import { useNowMinute } from "../hooks/useNowMinute";
206206
import { useNewThreadHandler } from "../hooks/useHandleNewThread";
207+
import { useThreadActions } from "../hooks/useThreadActions";
207208
import { resolveAppModelSelectionForInstance } from "../modelSelection";
208209
import { confirmTerminalClose, isTerminalCloseConfirmPending } from "../lib/terminalCloseConfirm";
209210
import { getTerminalFocusOwner } from "../lib/terminalFocus";
@@ -1257,6 +1258,7 @@ function ChatViewContent(props: ChatViewProps) {
12571258
const threadSyncPhase = routeKind === "server" ? (props.threadSyncPhase ?? null) : null;
12581259
const threadDetailLoading = threadSyncPhase === "loading";
12591260
const handleNewThread = useNewThreadHandler();
1261+
const { settleThread } = useThreadActions();
12601262
const routeThreadRef = useMemo(
12611263
() => scopeThreadRef(environmentId, threadId),
12621264
[environmentId, threadId],
@@ -4928,6 +4930,29 @@ function ChatViewContent(props: ChatViewProps) {
49284930
});
49294931
if (!command) return;
49304932

4933+
if (command === "thread.settle") {
4934+
event.preventDefault();
4935+
event.stopPropagation();
4936+
if (!isServerThread || !activeThreadRef || !supportsSettlement) return;
4937+
if (activeThreadSettled) {
4938+
void handleUnsettleActiveThread();
4939+
return;
4940+
}
4941+
4942+
void settleThread(activeThreadRef).then((result) => {
4943+
if (result._tag !== "Failure" || isAtomCommandInterrupted(result)) return;
4944+
const error = squashAtomCommandFailure(result);
4945+
toastManager.add(
4946+
stackedThreadToast({
4947+
type: "error",
4948+
title: "Failed to settle thread",
4949+
description: error instanceof Error ? error.message : "An error occurred.",
4950+
}),
4951+
);
4952+
});
4953+
return;
4954+
}
4955+
49314956
if (command === "terminal.toggle") {
49324957
event.preventDefault();
49334958
event.stopPropagation();
@@ -5031,6 +5056,8 @@ function ChatViewContent(props: ChatViewProps) {
50315056
activeProject,
50325057
activeRightPanelSurface,
50335058
addTerminalSurface,
5059+
activeThreadRef,
5060+
activeThreadSettled,
50345061
terminalUiState.terminalOpen,
50355062
terminalUiState.activeTerminalId,
50365063
activeThreadId,
@@ -5042,7 +5069,11 @@ function ChatViewContent(props: ChatViewProps) {
50425069
splitTerminal,
50435070
splitPanelTerminal,
50445071
keybindings,
5072+
handleUnsettleActiveThread,
5073+
isServerThread,
50455074
onToggleDiff,
5075+
settleThread,
5076+
supportsSettlement,
50465077
toggleRightPanel,
50475078
toggleRightPanelMaximized,
50485079
toggleTerminalVisibility,

‎apps/web/src/routes/_chat.tsx‎

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
22
import { useAtomValue } from "@effect/atom-react";
3-
import { scopedThreadKey } from "@t3tools/client-runtime/environment";
4-
import {
5-
isAtomCommandInterrupted,
6-
squashAtomCommandFailure,
7-
} from "@t3tools/client-runtime/state/runtime";
8-
import { effectiveSettled } from "@t3tools/client-runtime/state/thread-settled";
93
import { useEffect, useMemo } from "react";
104

115
import { isCommandPaletteOpen } from "../commandPaletteBus";
126
import { useClientSettings, useLegacySidebarEnabled } from "../hooks/useSettings";
137
import { openCommandPalette } from "../commandPaletteBus";
14-
import { readEnvironmentSupportsSettlement, readThreadShell, useProjects } from "../state/entities";
8+
import { useProjects } from "../state/entities";
159
import { usePrimaryEnvironmentId } from "../state/environments";
1610
import { selectProjectGroupingSettings } from "../logicalProject";
1711
import { buildSidebarProjectSnapshots } from "../sidebarProjectGrouping";
1812
import { dispatchPreviewAction } from "../components/preview/previewActionBus";
1913
import { useHandleNewThread } from "../hooks/useHandleNewThread";
20-
import { useThreadActions } from "../hooks/useThreadActions";
2114
import { startNewThreadFromContext } from "../lib/chatThreadActions";
2215
import { isPreviewFocused } from "../lib/previewFocus";
2316
import { isTerminalFocused } from "../lib/terminalFocus";
@@ -26,8 +19,6 @@ import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../termina
2619
import { isPreviewSupportedInRuntime } from "../previewStateStore";
2720
import { selectActiveRightPanel, useRightPanelStore } from "../rightPanelStore";
2821
import { useThreadSelectionStore } from "../threadSelectionStore";
29-
import { threadChangeRequestSnapshotsAtom } from "../components/ThreadStatusIndicators";
30-
import { appAtomRegistry } from "../rpc/atomRegistry";
3122
import { stackedThreadToast, toastManager } from "~/components/ui/toast";
3223
import { primaryServerKeybindingsAtom } from "~/state/server";
3324

@@ -36,12 +27,9 @@ function ChatRouteGlobalShortcuts() {
3627
const selectedThreadKeysSize = useThreadSelectionStore((state) => state.selectedThreadKeys.size);
3728
const { activeDraftThread, activeThread, defaultProjectRef, handleNewThread, routeThreadRef } =
3829
useHandleNewThread();
39-
const { settleThread, unsettleThread } = useThreadActions();
4030
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
4131
const legacySidebarEnabled = useLegacySidebarEnabled();
4232
const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings);
43-
const autoSettleAfterDays = useClientSettings((settings) => settings.sidebarAutoSettleAfterDays);
44-
const autoSettleOnMerge = useClientSettings((settings) => settings.sidebarAutoSettleOnMerge);
4533
const projects = useProjects();
4634
const primaryEnvironmentId = usePrimaryEnvironmentId();
4735
const projectGroupCount = useMemo(
@@ -120,45 +108,6 @@ function ChatRouteGlobalShortcuts() {
120108
return;
121109
}
122110

123-
if (command === "thread.settle") {
124-
event.preventDefault();
125-
event.stopPropagation();
126-
if (!routeThreadRef) return;
127-
if (!readEnvironmentSupportsSettlement(routeThreadRef.environmentId)) return;
128-
129-
const thread = readThreadShell(routeThreadRef);
130-
if (!thread) return;
131-
132-
const snapshot = appAtomRegistry
133-
.get(threadChangeRequestSnapshotsAtom)
134-
.get(scopedThreadKey(routeThreadRef));
135-
const changeRequest =
136-
snapshot != null && (thread.worktreePath === null || snapshot.branch === thread.branch)
137-
? snapshot.pr
138-
: null;
139-
const settled = effectiveSettled(thread, {
140-
now: `${new Date().toISOString().slice(0, 16)}:00.000Z`,
141-
autoSettleAfterDays,
142-
autoSettleOnMerge,
143-
changeRequest,
144-
});
145-
146-
void (settled ? unsettleThread(routeThreadRef) : settleThread(routeThreadRef)).then(
147-
(result) => {
148-
if (result._tag !== "Failure" || isAtomCommandInterrupted(result)) return;
149-
const error = squashAtomCommandFailure(result);
150-
toastManager.add(
151-
stackedThreadToast({
152-
type: "error",
153-
title: settled ? "Failed to un-settle thread" : "Failed to settle thread",
154-
description: error instanceof Error ? error.message : "An error occurred.",
155-
}),
156-
);
157-
},
158-
);
159-
return;
160-
}
161-
162111
if (command === "preview.toggle") {
163112
event.preventDefault();
164113
event.stopPropagation();
@@ -210,8 +159,6 @@ function ChatRouteGlobalShortcuts() {
210159
}, [
211160
activeDraftThread,
212161
activeThread,
213-
autoSettleAfterDays,
214-
autoSettleOnMerge,
215162
clearSelection,
216163
handleNewThread,
217164
keybindings,
@@ -220,10 +167,8 @@ function ChatRouteGlobalShortcuts() {
220167
projectGroupCount,
221168
routeThreadRef,
222169
selectedThreadKeysSize,
223-
settleThread,
224170
legacySidebarEnabled,
225171
terminalOpen,
226-
unsettleThread,
227172
]);
228173

229174
return null;

0 commit comments

Comments
 (0)