TypeScript
fix(web): find in thread opens from the thread title menu, so phones can reach it (#22352)
Mantas Kantautasa03e630705bc
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 665bb2fc5f5..1bf6f9b0fc0 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -2636,6 +2636,11 @@ export default function ChatView(props: ChatViewProps) {: EMPTY_PROVIDER_SKILLS;const threadFindEnabled = isServerThread && serverConfig?.threadFind === true;const isThreadFindActive = useThreadFindOpen(activeThreadRef, threadFindEnabled);+ const openThreadFindStable = useStableCallback((threadRef: ScopedThreadRef) => {+ if (threadFindEnabled && scopedThreadKey(threadRef) === activeThreadKey) {+ openThreadFind(activeThreadKey);+ }+ });useChatShortcuts({enabled: activeThreadId !== null && !backgroundThread,@@ -3241,6 +3246,7 @@ export default function ChatView(props: ChatViewProps) {{...(activeDraftLogicalProjectKey? { onOpenProjectSettings: handleOpenDraftProjectSettingsStable }: {})}+ {...(threadFindEnabled ? { onFindInThread: openThreadFindStable } : {})}/></header>diff --git a/apps/web/src/components/chat/ChatHeader.tsx b/apps/web/src/components/chat/ChatHeader.tsxindex ec92540efd1..144402d1dfe 100644--- a/apps/web/src/components/chat/ChatHeader.tsx+++ b/apps/web/src/components/chat/ChatHeader.tsx@@ -1,6 +1,7 @@import {AuthOrchestrationOperateScope,type EnvironmentId,+ type ScopedThreadRef,type ThreadId,} from "@t3tools/contracts";import { scopeThreadRef } from "@t3tools/client-runtime/environment";@@ -54,6 +55,7 @@ interface ChatHeaderProps {rightPanelOpen: boolean;onNewThreadInProject: () => void;onOpenProjectSettings?: (() => void) | undefined;+ onFindInThread?: ((threadRef: ScopedThreadRef) => void) | undefined;}function resolveRenameCommit(input: {@@ -80,6 +82,7 @@ export const ChatHeader = memo(function ChatHeader({rightPanelOpen,onNewThreadInProject,onOpenProjectSettings,+ onFindInThread,}: ChatHeaderProps) {const activeProjectName = activeProject?.isScratch ? "No project" : activeProject?.title;const activeProjectCwd = activeProject?.workspaceRoot ?? null;@@ -196,6 +199,7 @@ export const ChatHeader = memo(function ChatHeader({threadRef: isServerThread ? activeThreadRef : null,projectCwd: activeProjectCwd,onStartRename: startRename,+ onFind: onFindInThread,canShareWithGuest,});const titleButtonRef = useRef<HTMLButtonElement | null>(null);diff --git a/apps/web/src/components/threadActionMenu.logic.ts b/apps/web/src/components/threadActionMenu.logic.tsindex 3c4626c1ea1..ac4ef649ed0 100644--- a/apps/web/src/components/threadActionMenu.logic.ts+++ b/apps/web/src/components/threadActionMenu.logic.ts@@ -2,6 +2,7 @@ import type { ContextMenuItem } from "@t3tools/contracts";import type { SnoozePreset } from "@t3tools/client-runtime/state/thread-settled";export type ThreadActionMenuId =+ | "find"| "new-thread-on-branch"| "filter-by-project"| "turn-into-project"@@ -68,6 +69,7 @@ export function buildDraftActionMenuItems(options: {export interface ThreadActionMenuState {readonly canOperate: boolean;+ readonly canFind?: boolean;readonly branch: string | null;readonly projectFilter: {readonly label: string;@@ -98,6 +100,7 @@ export interface ThreadActionMenuState {/** Local navigation, read markers, and copying remain available to read-only clients. */export function threadActionRequiresOperate(action: ThreadActionMenuId): boolean {return ![+ "find","new-thread-on-branch","project-settings","mark-unread",@@ -114,6 +117,9 @@ export function buildThreadActionMenuItems(state: ThreadActionMenuState,): ReadonlyArray<ContextMenuItem<ThreadActionMenuId>> {const items: ReadonlyArray<ContextMenuItem<ThreadActionMenuId>> = [+ ...(state.canFind+ ? [{ id: "find" as const, label: "Find in thread", icon: "text-search" }]+ : []),...(state.branch? [{diff --git a/apps/web/src/contextMenuFallback.ts b/apps/web/src/contextMenuFallback.tsindex eece920cba6..b63fc5b3ff7 100644--- a/apps/web/src/contextMenuFallback.ts+++ b/apps/web/src/contextMenuFallback.ts@@ -150,6 +150,13 @@ const ICON_PATHS: Record<string, ReadonlyArray<{ tag: string; attrs: Record<stri{ tag: "path", attrs: { d: "M3 5a2 2 0 0 0 2 2h3" } },{ tag: "path", attrs: { d: "M3 3v13a2 2 0 0 0 2 2h3" } },],+ "text-search": [+ { tag: "path", attrs: { d: "M21 5H3" } },+ { tag: "path", attrs: { d: "M10 12H3" } },+ { tag: "path", attrs: { d: "M10 19H3" } },+ { tag: "circle", attrs: { cx: "17", cy: "15", r: "3" } },+ { tag: "path", attrs: { d: "m21 19-1.9-1.9" } },+ ],trash: [{ tag: "path", attrs: { d: "M3 6h18" } },{ tag: "path", attrs: { d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" } },diff --git a/apps/web/src/hooks/useThreadActionMenu.test.ts b/apps/web/src/hooks/useThreadActionMenu.test.tsindex e87092d59c3..3c8255b04c0 100644--- a/apps/web/src/hooks/useThreadActionMenu.test.ts+++ b/apps/web/src/hooks/useThreadActionMenu.test.ts@@ -149,11 +149,12 @@ const target = {threadId: ThreadId.make("thread"),};const position = { x: 10, y: 20 };-const createMenu = () =>+const createMenu = (options: { readonly onFind?: (threadRef: typeof target) => void } = {}) =>useThreadActionMenu({threadRef: target,projectCwd: "/project",onStartRename: () => recordEffect("rename"),+ onFind: options.onFind,canShareWithGuest: false,});@@ -178,4 +179,18 @@ describe("thread menu permissions", () => {expect(state.effects).toEqual([]);},);++ it("offers find only to a header that can open it, without task permission", async () => {+ createMenu().openMenu(position);+ expect(state.show.mock.calls[0]![0].some((item) => item.id === "find")).toBe(false);+ state.show.mockResolvedValue("find");+ const onFind = vi.fn(() => recordEffect("find"));+ createMenu({ onFind }).openMenu(position);+ await state.completed.promise;+ const items = state.show.mock.calls[1]![0];+ expect(items[0]).toMatchObject({ id: "find", label: "Find in thread" });+ expect(items[0]?.disabled).not.toBe(true);+ expect(state.effects).toEqual(["find"]);+ expect(onFind).toHaveBeenCalledExactlyOnceWith(target);+ });});diff --git a/apps/web/src/hooks/useThreadActionMenu.ts b/apps/web/src/hooks/useThreadActionMenu.tsindex 0e25cebeef8..cddef6046cf 100644--- a/apps/web/src/hooks/useThreadActionMenu.ts+++ b/apps/web/src/hooks/useThreadActionMenu.ts@@ -61,9 +61,10 @@ export function useThreadActionMenu(input: {readonly threadRef: ScopedThreadRef | null;readonly projectCwd: string | null;readonly onStartRename: () => void;+ readonly onFind?: ((threadRef: ScopedThreadRef) => void) | undefined;readonly canShareWithGuest: boolean;}) {- const { threadRef, projectCwd, onStartRename, canShareWithGuest } = input;+ const { threadRef, projectCwd, onStartRename, onFind, canShareWithGuest } = input;const router = useRouter();const projects = useProjects();const primaryEnvironmentId = usePrimaryEnvironmentId();@@ -133,6 +134,7 @@ export function useThreadActionMenu(input: {const snoozePresets = resolveSnoozePresets(now, timestampFormat, threadRef.environmentId);const items = buildThreadActionMenuItems({canOperate: readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope),+ canFind: onFind !== undefined,branch: thread.branch ?? null,projectFilter: null,isPinned: thread.pinnedAt != null,@@ -187,6 +189,9 @@ export function useThreadActionMenu(input: {}};switch (action) {+ case "find":+ onFind?.(threadRef);+ return;case "project-settings": {const project = projects.find((candidate) =>