Skip to content

Commit e25227a

Browse files
refactor(web): ChatView's project clone banner lives in useProjectCloneBanner
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d9551c4 commit e25227a

2 files changed

Lines changed: 138 additions & 110 deletions

File tree

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

Lines changed: 4 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useProjectCloneBanner } from "./chat/useProjectCloneBanner";
12
import { useAttachmentPreviewHandoff } from "./chat/useAttachmentPreviewHandoff";
23
import { useTimelineRewind } from "./chat/useTimelineRewind";
34
import { useThreadLifecycle } from "./chat/useThreadLifecycle";
@@ -175,7 +176,7 @@ import { makeWorkspaceFileDropHandlers } from "./chat/workspaceFileDrop";
175176
import { isEditableFocused } from "../lib/editableFocus";
176177
import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
177178
import { shortcutLabelForCommand } from "../keybindings";
178-
import { PaperclipIcon, ChevronDownIcon, DownloadIcon } from "lucide-react";
179+
import { PaperclipIcon, ChevronDownIcon } from "lucide-react";
179180
import { cn } from "~/lib/utils";
180181
import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar";
181182
import { stackedThreadToast, toastManager } from "./ui/toast";
@@ -197,7 +198,6 @@ import {
197198
import { useNowMinute } from "../hooks/useNowMinute";
198199
import { usePanelAnimationSettings, usePanelPresence } from "../panelAnimations";
199200
import { useNewThreadHandler } from "../hooks/useHandleNewThread";
200-
import { useRemoveClonedProject } from "../hooks/useRemoveClonedProject";
201201
import { useOpenPanelPullRequestUrl } from "../hooks/useOpenPanelPullRequestUrl";
202202
import { resolveAppModelSelectionForInstance } from "../modelSelection";
203203
import { isPreviewFocused } from "../lib/previewFocus";
@@ -234,10 +234,6 @@ import {
234234
import { threadEnvironment } from "../state/threads";
235235
import { resolveProviderSkillsForCwd } from "@t3tools/client-runtime/providerSkills";
236236
import { vcsEnvironment } from "../state/vcs";
237-
import { sourceControlEnvironment } from "../state/sourceControl";
238-
import { useProjectClone } from "../state/projectClones";
239-
import { projectCloneDisplayName, projectCloneProgressSummary } from "@t3tools/contracts";
240-
import { dismissProjectFileCopy, useProjectFileCopy } from "../lib/addProjectToMachine";
241237
import {
242238
type EnvironmentPresentation,
243239
useEnvironmentProviders,
@@ -1116,110 +1112,8 @@ export default function ChatView(props: ChatViewProps) {
11161112
activeProject ?? undefined,
11171113
);
11181114
const activeProjectScripts = activeProject ? resolveProjectScripts(settings, activeProject) : [];
1119-
const activeProjectClone = useProjectClone(activeProjectRef);
1120-
const cancelProjectClone = useAtomCommand(sourceControlEnvironment.cancelProjectClone, {
1121-
reportFailure: false,
1122-
});
1123-
const retryProjectClone = useAtomCommand(sourceControlEnvironment.retryProjectClone, {
1124-
reportFailure: false,
1125-
});
1126-
const removeClonedProject = useRemoveClonedProject();
1127-
const runProjectCloneAction = async (
1128-
title: string,
1129-
action: () => Promise<AtomCommandResult<unknown, unknown>>,
1130-
): Promise<void> => {
1131-
const result = await action();
1132-
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
1133-
const error = squashAtomCommandFailure(result);
1134-
toastManager.add(
1135-
stackedThreadToast({
1136-
type: "error",
1137-
title,
1138-
description: error instanceof Error ? error.message : "An error occurred.",
1139-
}),
1140-
);
1141-
}
1142-
};
1143-
const runProjectCloneActionStable = useStableCallback(runProjectCloneAction);
1144-
const activeProjectFileCopy = useProjectFileCopy(activeProjectRef);
1145-
const projectCloneSendBlockReason =
1146-
activeProjectClone?.phase === "running"
1147-
? "Cloning repository"
1148-
: activeProjectClone !== null && activeProjectClone.phase !== "done"
1149-
? "Repository not cloned"
1150-
: activeProjectFileCopy?.phase === "copying"
1151-
? "Copying files"
1152-
: null;
1153-
const projectCloneBannerItem = (() => {
1154-
if (activeProjectFileCopy?.phase === "failed" && activeProjectRef) {
1155-
return {
1156-
id: `project-file-copy:${activeProjectRef.projectId}`,
1157-
variant: "error",
1158-
icon: <DownloadIcon />,
1159-
title: activeProjectFileCopy.title,
1160-
description: activeProjectFileCopy.failures.join("\n"),
1161-
onDismiss: () => dismissProjectFileCopy(activeProjectRef),
1162-
};
1163-
}
1164-
if (!activeProjectClone || !activeProjectRef || activeProjectClone.phase === "done") {
1165-
return null;
1166-
}
1167-
const name = projectCloneDisplayName(activeProjectClone);
1168-
const { environmentId, projectId } = activeProjectRef;
1169-
if (activeProjectClone.phase === "running") {
1170-
return {
1171-
id: `project-clone:${projectId}`,
1172-
variant: "info",
1173-
priority: "activity",
1174-
icon: <DownloadIcon />,
1175-
title: `Cloning ${name}`,
1176-
description: projectCloneProgressSummary(activeProjectClone),
1177-
actions: (
1178-
<Button
1179-
size="xs"
1180-
variant="ghost"
1181-
onClick={() =>
1182-
void runProjectCloneActionStable("Failed to cancel clone", () =>
1183-
cancelProjectClone({ environmentId, input: { projectId } }),
1184-
)
1185-
}
1186-
>
1187-
Cancel
1188-
</Button>
1189-
),
1190-
};
1191-
}
1192-
const cancelled = activeProjectClone.phase === "cancelled";
1193-
return {
1194-
id: `project-clone:${projectId}`,
1195-
variant: cancelled ? "warning" : "error",
1196-
icon: <DownloadIcon />,
1197-
title: cancelled ? `Cancelled cloning ${name}` : `Failed to clone ${name}`,
1198-
description: cancelled ? "Retry to bring in the repository." : activeProjectClone.error,
1199-
actions: (
1200-
<>
1201-
<Button
1202-
size="xs"
1203-
variant="ghost"
1204-
onClick={() => void removeClonedProject({ environmentId, projectId })}
1205-
>
1206-
Remove project
1207-
</Button>
1208-
<Button
1209-
size="xs"
1210-
variant="ghost"
1211-
onClick={() =>
1212-
void runProjectCloneActionStable("Failed to retry clone", () =>
1213-
retryProjectClone({ environmentId, input: { projectId } }),
1214-
)
1215-
}
1216-
>
1217-
Retry
1218-
</Button>
1219-
</>
1220-
),
1221-
};
1222-
})() as ComposerBannerStackItem | null;
1115+
const { projectCloneBannerItem, projectCloneSendBlockReason } =
1116+
useProjectCloneBanner(activeProjectRef);
12231117
const activeProjectDefaultModelSelection = activeProjectSettings.settings.defaultModelSelection;
12241118
const handleNewThreadInActiveProject = () => {
12251119
startNewThreadForProject(activeProjectRef, handleNewThread);
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import { useStableCallback } from "../../hooks/useStableCallback";
2+
import {
3+
isAtomCommandInterrupted,
4+
squashAtomCommandFailure,
5+
type AtomCommandResult,
6+
} from "@t3tools/client-runtime/state/runtime";
7+
import { DownloadIcon } from "lucide-react";
8+
import { stackedThreadToast, toastManager } from "../ui/toast";
9+
import { useRemoveClonedProject } from "../../hooks/useRemoveClonedProject";
10+
import { sourceControlEnvironment } from "../../state/sourceControl";
11+
import { useProjectClone } from "../../state/projectClones";
12+
import {
13+
projectCloneDisplayName,
14+
projectCloneProgressSummary,
15+
type ScopedProjectRef,
16+
} from "@t3tools/contracts";
17+
import { dismissProjectFileCopy, useProjectFileCopy } from "../../lib/addProjectToMachine";
18+
import { type ComposerBannerStackItem } from "./ComposerBannerStack";
19+
import { useAtomCommand } from "../../state/use-atom-command";
20+
import { Button } from "../ui/button";
21+
/**
22+
* A project still being cloned or copied into place: the composer banner with its cancel,
23+
* retry, and remove actions, and the reason sending waits until it is done.
24+
*/
25+
export function useProjectCloneBanner(activeProjectRef: ScopedProjectRef | null) {
26+
const activeProjectClone = useProjectClone(activeProjectRef);
27+
const cancelProjectClone = useAtomCommand(sourceControlEnvironment.cancelProjectClone, {
28+
reportFailure: false,
29+
});
30+
const retryProjectClone = useAtomCommand(sourceControlEnvironment.retryProjectClone, {
31+
reportFailure: false,
32+
});
33+
const removeClonedProject = useRemoveClonedProject();
34+
const runProjectCloneAction = async (
35+
title: string,
36+
action: () => Promise<AtomCommandResult<unknown, unknown>>,
37+
): Promise<void> => {
38+
const result = await action();
39+
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
40+
const error = squashAtomCommandFailure(result);
41+
toastManager.add(
42+
stackedThreadToast({
43+
type: "error",
44+
title,
45+
description: error instanceof Error ? error.message : "An error occurred.",
46+
}),
47+
);
48+
}
49+
};
50+
const runProjectCloneActionStable = useStableCallback(runProjectCloneAction);
51+
const activeProjectFileCopy = useProjectFileCopy(activeProjectRef);
52+
const projectCloneSendBlockReason =
53+
activeProjectClone?.phase === "running"
54+
? "Cloning repository"
55+
: activeProjectClone !== null && activeProjectClone.phase !== "done"
56+
? "Repository not cloned"
57+
: activeProjectFileCopy?.phase === "copying"
58+
? "Copying files"
59+
: null;
60+
const projectCloneBannerItem = (() => {
61+
if (activeProjectFileCopy?.phase === "failed" && activeProjectRef) {
62+
return {
63+
id: `project-file-copy:${activeProjectRef.projectId}`,
64+
variant: "error",
65+
icon: <DownloadIcon />,
66+
title: activeProjectFileCopy.title,
67+
description: activeProjectFileCopy.failures.join("\n"),
68+
onDismiss: () => dismissProjectFileCopy(activeProjectRef),
69+
};
70+
}
71+
if (!activeProjectClone || !activeProjectRef || activeProjectClone.phase === "done") {
72+
return null;
73+
}
74+
const name = projectCloneDisplayName(activeProjectClone);
75+
const { environmentId, projectId } = activeProjectRef;
76+
if (activeProjectClone.phase === "running") {
77+
return {
78+
id: `project-clone:${projectId}`,
79+
variant: "info",
80+
priority: "activity",
81+
icon: <DownloadIcon />,
82+
title: `Cloning ${name}`,
83+
description: projectCloneProgressSummary(activeProjectClone),
84+
actions: (
85+
<Button
86+
size="xs"
87+
variant="ghost"
88+
onClick={() =>
89+
void runProjectCloneActionStable("Failed to cancel clone", () =>
90+
cancelProjectClone({ environmentId, input: { projectId } }),
91+
)
92+
}
93+
>
94+
Cancel
95+
</Button>
96+
),
97+
};
98+
}
99+
const cancelled = activeProjectClone.phase === "cancelled";
100+
return {
101+
id: `project-clone:${projectId}`,
102+
variant: cancelled ? "warning" : "error",
103+
icon: <DownloadIcon />,
104+
title: cancelled ? `Cancelled cloning ${name}` : `Failed to clone ${name}`,
105+
description: cancelled ? "Retry to bring in the repository." : activeProjectClone.error,
106+
actions: (
107+
<>
108+
<Button
109+
size="xs"
110+
variant="ghost"
111+
onClick={() => void removeClonedProject({ environmentId, projectId })}
112+
>
113+
Remove project
114+
</Button>
115+
<Button
116+
size="xs"
117+
variant="ghost"
118+
onClick={() =>
119+
void runProjectCloneActionStable("Failed to retry clone", () =>
120+
retryProjectClone({ environmentId, input: { projectId } }),
121+
)
122+
}
123+
>
124+
Retry
125+
</Button>
126+
</>
127+
),
128+
};
129+
})() as ComposerBannerStackItem | null;
130+
return {
131+
projectCloneBannerItem,
132+
projectCloneSendBlockReason,
133+
};
134+
}

0 commit comments

Comments
 (0)