Skip to content

Commit a03e630

Browse files
fix(web): find in thread opens from the thread title menu, so phones can reach it (pingdotgg#22352)
Co-authored-by: maria-rcks <[email protected]>
1 parent 5aa81a3 commit a03e630

6 files changed

Lines changed: 45 additions & 2 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,6 +2636,11 @@ export default function ChatView(props: ChatViewProps) {
26362636
: EMPTY_PROVIDER_SKILLS;
26372637
const threadFindEnabled = isServerThread && serverConfig?.threadFind === true;
26382638
const isThreadFindActive = useThreadFindOpen(activeThreadRef, threadFindEnabled);
2639+
const openThreadFindStable = useStableCallback((threadRef: ScopedThreadRef) => {
2640+
if (threadFindEnabled && scopedThreadKey(threadRef) === activeThreadKey) {
2641+
openThreadFind(activeThreadKey);
2642+
}
2643+
});
26392644

26402645
useChatShortcuts({
26412646
enabled: activeThreadId !== null && !backgroundThread,
@@ -3241,6 +3246,7 @@ export default function ChatView(props: ChatViewProps) {
32413246
{...(activeDraftLogicalProjectKey
32423247
? { onOpenProjectSettings: handleOpenDraftProjectSettingsStable }
32433248
: {})}
3249+
{...(threadFindEnabled ? { onFindInThread: openThreadFindStable } : {})}
32443250
/>
32453251
</header>
32463252

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

Lines changed: 4 additions & 0 deletions
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";
@@ -54,6 +55,7 @@ interface ChatHeaderProps {
5455
rightPanelOpen: boolean;
5556
onNewThreadInProject: () => void;
5657
onOpenProjectSettings?: (() => void) | undefined;
58+
onFindInThread?: ((threadRef: ScopedThreadRef) => void) | undefined;
5759
}
5860

5961
function resolveRenameCommit(input: {
@@ -80,6 +82,7 @@ export const ChatHeader = memo(function ChatHeader({
8082
rightPanelOpen,
8183
onNewThreadInProject,
8284
onOpenProjectSettings,
85+
onFindInThread,
8386
}: ChatHeaderProps) {
8487
const activeProjectName = activeProject?.isScratch ? "No project" : activeProject?.title;
8588
const activeProjectCwd = activeProject?.workspaceRoot ?? null;
@@ -196,6 +199,7 @@ export const ChatHeader = memo(function ChatHeader({
196199
threadRef: isServerThread ? activeThreadRef : null,
197200
projectCwd: activeProjectCwd,
198201
onStartRename: startRename,
202+
onFind: onFindInThread,
199203
canShareWithGuest,
200204
});
201205
const titleButtonRef = useRef<HTMLButtonElement | null>(null);

‎apps/web/src/components/threadActionMenu.logic.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ContextMenuItem } from "@t3tools/contracts";
22
import type { SnoozePreset } from "@t3tools/client-runtime/state/thread-settled";
33

44
export type ThreadActionMenuId =
5+
| "find"
56
| "new-thread-on-branch"
67
| "filter-by-project"
78
| "turn-into-project"
@@ -68,6 +69,7 @@ export function buildDraftActionMenuItems(options: {
6869

6970
export interface ThreadActionMenuState {
7071
readonly canOperate: boolean;
72+
readonly canFind?: boolean;
7173
readonly branch: string | null;
7274
readonly projectFilter: {
7375
readonly label: string;
@@ -98,6 +100,7 @@ export interface ThreadActionMenuState {
98100
/** Local navigation, read markers, and copying remain available to read-only clients. */
99101
export function threadActionRequiresOperate(action: ThreadActionMenuId): boolean {
100102
return ![
103+
"find",
101104
"new-thread-on-branch",
102105
"project-settings",
103106
"mark-unread",
@@ -114,6 +117,9 @@ export function buildThreadActionMenuItems(
114117
state: ThreadActionMenuState,
115118
): ReadonlyArray<ContextMenuItem<ThreadActionMenuId>> {
116119
const items: ReadonlyArray<ContextMenuItem<ThreadActionMenuId>> = [
120+
...(state.canFind
121+
? [{ id: "find" as const, label: "Find in thread", icon: "text-search" }]
122+
: []),
117123
...(state.branch
118124
? [
119125
{

‎apps/web/src/contextMenuFallback.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ const ICON_PATHS: Record<string, ReadonlyArray<{ tag: string; attrs: Record<stri
150150
{ tag: "path", attrs: { d: "M3 5a2 2 0 0 0 2 2h3" } },
151151
{ tag: "path", attrs: { d: "M3 3v13a2 2 0 0 0 2 2h3" } },
152152
],
153+
"text-search": [
154+
{ tag: "path", attrs: { d: "M21 5H3" } },
155+
{ tag: "path", attrs: { d: "M10 12H3" } },
156+
{ tag: "path", attrs: { d: "M10 19H3" } },
157+
{ tag: "circle", attrs: { cx: "17", cy: "15", r: "3" } },
158+
{ tag: "path", attrs: { d: "m21 19-1.9-1.9" } },
159+
],
153160
trash: [
154161
{ tag: "path", attrs: { d: "M3 6h18" } },
155162
{ tag: "path", attrs: { d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" } },

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,12 @@ const target = {
149149
threadId: ThreadId.make("thread"),
150150
};
151151
const position = { x: 10, y: 20 };
152-
const createMenu = () =>
152+
const createMenu = (options: { readonly onFind?: (threadRef: typeof target) => void } = {}) =>
153153
useThreadActionMenu({
154154
threadRef: target,
155155
projectCwd: "/project",
156156
onStartRename: () => recordEffect("rename"),
157+
onFind: options.onFind,
157158
canShareWithGuest: false,
158159
});
159160

@@ -178,4 +179,18 @@ describe("thread menu permissions", () => {
178179
expect(state.effects).toEqual([]);
179180
},
180181
);
182+
183+
it("offers find only to a header that can open it, without task permission", async () => {
184+
createMenu().openMenu(position);
185+
expect(state.show.mock.calls[0]![0].some((item) => item.id === "find")).toBe(false);
186+
state.show.mockResolvedValue("find");
187+
const onFind = vi.fn(() => recordEffect("find"));
188+
createMenu({ onFind }).openMenu(position);
189+
await state.completed.promise;
190+
const items = state.show.mock.calls[1]![0];
191+
expect(items[0]).toMatchObject({ id: "find", label: "Find in thread" });
192+
expect(items[0]?.disabled).not.toBe(true);
193+
expect(state.effects).toEqual(["find"]);
194+
expect(onFind).toHaveBeenCalledExactlyOnceWith(target);
195+
});
181196
});

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ export function useThreadActionMenu(input: {
6161
readonly threadRef: ScopedThreadRef | null;
6262
readonly projectCwd: string | null;
6363
readonly onStartRename: () => void;
64+
readonly onFind?: ((threadRef: ScopedThreadRef) => void) | undefined;
6465
readonly canShareWithGuest: boolean;
6566
}) {
66-
const { threadRef, projectCwd, onStartRename, canShareWithGuest } = input;
67+
const { threadRef, projectCwd, onStartRename, onFind, canShareWithGuest } = input;
6768
const router = useRouter();
6869
const projects = useProjects();
6970
const primaryEnvironmentId = usePrimaryEnvironmentId();
@@ -133,6 +134,7 @@ export function useThreadActionMenu(input: {
133134
const snoozePresets = resolveSnoozePresets(now, timestampFormat, threadRef.environmentId);
134135
const items = buildThreadActionMenuItems({
135136
canOperate: readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope),
137+
canFind: onFind !== undefined,
136138
branch: thread.branch ?? null,
137139
projectFilter: null,
138140
isPinned: thread.pinnedAt != null,
@@ -187,6 +189,9 @@ export function useThreadActionMenu(input: {
187189
}
188190
};
189191
switch (action) {
192+
case "find":
193+
onFind?.(threadRef);
194+
return;
190195
case "project-settings": {
191196
const project = projects.find(
192197
(candidate) =>

0 commit comments

Comments
 (0)