Skip to content

Commit 542ee29

Browse files
committed
fix(web): keep thread find menu bound to its thread
1 parent b45724c commit 542ee29

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,8 +2628,10 @@ export default function ChatView(props: ChatViewProps) {
26282628
const threadFindEnabled =
26292629
isServerThread && serverConfig?.threadFind === true && !paintOnlyDisplayedTimeline;
26302630
const isThreadFindActive = useThreadFindOpen(activeThreadRef, threadFindEnabled);
2631-
const openThreadFindStable = useStableCallback(() => {
2632-
if (activeThreadKey !== null) openThreadFind(activeThreadKey);
2631+
const openThreadFindStable = useStableCallback((threadRef: ScopedThreadRef) => {
2632+
if (threadFindEnabled && scopedThreadKey(threadRef) === activeThreadKey) {
2633+
openThreadFind(activeThreadKey);
2634+
}
26332635
});
26342636

26352637
useChatShortcuts({

‎apps/web/src/components/chat/ChatHeader.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
AuthOrchestrationOperateScope,
33
type EnvironmentId,
4+
type ScopedThreadRef,
45
type ThreadId,
56
} from "@t3tools/contracts";
67
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
@@ -52,7 +53,7 @@ interface ChatHeaderProps {
5253
rightPanelOpen: boolean;
5354
onNewThreadInProject: () => void;
5455
onOpenProjectSettings?: (() => void) | undefined;
55-
onFindInThread?: (() => void) | undefined;
56+
onFindInThread?: ((threadRef: ScopedThreadRef) => void) | undefined;
5657
}
5758

5859
function resolveRenameCommit(input: {

‎apps/web/src/hooks/useThreadActionMenu.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ const target = {
151151
threadId: ThreadId.make("thread"),
152152
};
153153
const position = { x: 10, y: 20 };
154-
const createMenu = (options: { readonly withFind?: boolean } = {}) =>
154+
const createMenu = (options: { readonly onFind?: (threadRef: typeof target) => void } = {}) =>
155155
useThreadActionMenu({
156156
threadRef: target,
157157
projectCwd: "/project",
158158
onStartRename: () => recordEffect("rename"),
159-
...(options.withFind ? { onFind: () => recordEffect("find") } : {}),
159+
onFind: options.onFind,
160160
canShareWithGuest: false,
161161
});
162162

@@ -186,11 +186,13 @@ describe("thread menu permissions", () => {
186186
createMenu().openMenu(position);
187187
expect(state.show.mock.calls[0]![0].some((item) => item.id === "find")).toBe(false);
188188
state.show.mockResolvedValue("find");
189-
createMenu({ withFind: true }).openMenu(position);
189+
const onFind = vi.fn(() => recordEffect("find"));
190+
createMenu({ onFind }).openMenu(position);
190191
await state.completed.promise;
191192
const items = state.show.mock.calls[1]![0];
192193
expect(items[0]).toMatchObject({ id: "find", label: "Find in thread" });
193194
expect(items[0]?.disabled).not.toBe(true);
194195
expect(state.effects).toEqual(["find"]);
196+
expect(onFind).toHaveBeenCalledExactlyOnceWith(target);
195197
});
196198
});

‎apps/web/src/hooks/useThreadActionMenu.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function useThreadActionMenu(input: {
6262
readonly threadRef: ScopedThreadRef | null;
6363
readonly projectCwd: string | null;
6464
readonly onStartRename: () => void;
65-
readonly onFind?: (() => void) | undefined;
65+
readonly onFind?: ((threadRef: ScopedThreadRef) => void) | undefined;
6666
readonly canShareWithGuest: boolean;
6767
}) {
6868
const { threadRef, projectCwd, onStartRename, onFind, canShareWithGuest } = input;
@@ -183,7 +183,7 @@ export function useThreadActionMenu(input: {
183183
};
184184
switch (action) {
185185
case "find":
186-
onFind?.();
186+
onFind?.(threadRef);
187187
return;
188188
case "project-settings": {
189189
const project = projects.find(

0 commit comments

Comments
 (0)