Skip to content

Commit 0477b11

Browse files
committed
review fixes
1 parent fb04ea4 commit 0477b11

5 files changed

Lines changed: 39 additions & 34 deletions

File tree

apps/code/src/renderer/features/command-center/components/CommandCenterSessionView.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,8 @@ export function CommandCenterSessionView({
1818
}: CommandCenterSessionViewProps) {
1919
const { requestFocus } = useDraftStore((s) => s.actions);
2020

21-
useSessionConnection({ taskId, task });
22-
23-
const {
24-
handleSendPrompt,
25-
handleCancelPrompt,
26-
handleRetry,
27-
handleNewSession,
28-
handleBashCommand,
29-
} = useSessionCallbacks({ taskId, task });
30-
3121
const {
22+
session,
3223
repoPath,
3324
isCloud,
3425
isRunning,
@@ -43,6 +34,16 @@ export function CommandCenterSessionView({
4334
errorMessage,
4435
} = useSessionViewState(taskId, task);
4536

37+
useSessionConnection({ taskId, task, session, repoPath, isCloud });
38+
39+
const {
40+
handleSendPrompt,
41+
handleCancelPrompt,
42+
handleRetry,
43+
handleNewSession,
44+
handleBashCommand,
45+
} = useSessionCallbacks({ taskId, task, session, repoPath });
46+
4647
useEffect(() => {
4748
requestFocus(taskId);
4849
}, [taskId, requestFocus]);

apps/code/src/renderer/features/sessions/hooks/useSessionCallbacks.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { tryExecuteCodeCommand } from "@features/message-editor/commands";
22
import { useDraftStore } from "@features/message-editor/stores/draftStore";
3-
import { useCwd } from "@features/sidebar/hooks/useCwd";
43
import { useTaskViewed } from "@features/sidebar/hooks/useTaskViewed";
54
import { trpcClient } from "@renderer/trpc/client";
65
import type { Task } from "@shared/types";
@@ -9,21 +8,24 @@ import { logger } from "@utils/logger";
98
import { toast } from "@utils/toast";
109
import { useCallback, useRef } from "react";
1110
import { getSessionService } from "../service/service";
12-
import { sessionStoreSetters, useSessionForTask } from "../stores/sessionStore";
11+
import type { AgentSession } from "../stores/sessionStore";
12+
import { sessionStoreSetters } from "../stores/sessionStore";
1313

1414
const log = logger.scope("session-callbacks");
1515

1616
interface UseSessionCallbacksOptions {
1717
taskId: string;
1818
task: Task;
19+
session: AgentSession | undefined;
20+
repoPath: string | null;
1921
}
2022

2123
export function useSessionCallbacks({
2224
taskId,
2325
task,
26+
session,
27+
repoPath,
2428
}: UseSessionCallbacksOptions) {
25-
const session = useSessionForTask(taskId);
26-
const repoPath = useCwd(taskId);
2729
const { markActivity, markAsViewed } = useTaskViewed();
2830
const { requestFocus, setPendingContent } = useDraftStore((s) => s.actions);
2931

apps/code/src/renderer/features/sessions/hooks/useSessionConnection.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import { useCwd } from "@features/sidebar/hooks/useCwd";
21
import { useTaskViewed } from "@features/sidebar/hooks/useTaskViewed";
3-
import { useWorkspace } from "@features/workspace/hooks/useWorkspace";
42
import { useConnectivity } from "@hooks/useConnectivity";
53
import { trpcClient } from "@renderer/trpc/client";
64
import type { Task } from "@shared/types";
75
import { useQueryClient } from "@tanstack/react-query";
86
import { logger } from "@utils/logger";
97
import { useEffect } from "react";
108
import { getSessionService } from "../service/service";
11-
import { useSessionForTask } from "../stores/sessionStore";
9+
import type { AgentSession } from "../stores/sessionStore";
1210
import { useChatTitleGenerator } from "./useChatTitleGenerator";
1311

1412
const log = logger.scope("session-connection");
@@ -18,22 +16,22 @@ const connectingTasks = new Set<string>();
1816
interface UseSessionConnectionOptions {
1917
taskId: string;
2018
task: Task;
19+
session: AgentSession | undefined;
20+
repoPath: string | null;
21+
isCloud: boolean;
2122
}
2223

2324
export function useSessionConnection({
2425
taskId,
2526
task,
27+
session,
28+
repoPath,
29+
isCloud,
2630
}: UseSessionConnectionOptions) {
27-
const session = useSessionForTask(taskId);
28-
const repoPath = useCwd(taskId);
29-
const workspace = useWorkspace(taskId);
3031
const queryClient = useQueryClient();
3132
const { markActivity } = useTaskViewed();
3233
const { isOnline } = useConnectivity();
3334

34-
const isCloud =
35-
workspace?.mode === "cloud" || task.latest_run?.environment === "cloud";
36-
3735
useChatTitleGenerator(taskId);
3836

3937
useEffect(() => {
@@ -111,5 +109,9 @@ export function useSessionConnection({
111109
.finally(() => {
112110
connectingTasks.delete(taskId);
113111
});
112+
113+
return () => {
114+
connectingTasks.delete(taskId);
115+
};
114116
}, [task, taskId, repoPath, session, markActivity, isOnline, isCloud]);
115117
}

apps/code/src/renderer/features/sessions/hooks/useSessionViewState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useSessionForTask } from "../stores/sessionStore";
66

77
export function useSessionViewState(taskId: string, task: Task) {
88
const session = useSessionForTask(taskId);
9-
const repoPath = useCwd(taskId);
9+
const repoPath = useCwd(taskId) ?? null;
1010
const workspace = useWorkspace(taskId);
1111

1212
const isCloud =

apps/code/src/renderer/features/task-detail/components/TaskLogsPanel.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,6 @@ export function TaskLogsPanel({ taskId, task }: TaskLogsPanelProps) {
3636

3737
const { requestFocus } = useDraftStore((s) => s.actions);
3838

39-
useSessionConnection({ taskId, task });
40-
41-
const {
42-
handleSendPrompt,
43-
handleCancelPrompt,
44-
handleRetry,
45-
handleNewSession,
46-
handleBashCommand,
47-
} = useSessionCallbacks({ taskId, task });
48-
4939
const {
5040
session,
5141
repoPath,
@@ -64,6 +54,16 @@ export function TaskLogsPanel({ taskId, task }: TaskLogsPanelProps) {
6454
errorMessage,
6555
} = useSessionViewState(taskId, task);
6656

57+
useSessionConnection({ taskId, task, session, repoPath, isCloud });
58+
59+
const {
60+
handleSendPrompt,
61+
handleCancelPrompt,
62+
handleRetry,
63+
handleNewSession,
64+
handleBashCommand,
65+
} = useSessionCallbacks({ taskId, task, session, repoPath });
66+
6767
const cloudStage = session?.cloudStage ?? null;
6868
const cloudOutput = session?.cloudOutput ?? null;
6969
const cloudErrorMessage = session?.cloudErrorMessage ?? null;

0 commit comments

Comments
 (0)