Skip to content

Commit 9dcdb7b

Browse files
Make document call component clickable (vercel#558)
1 parent f360ff9 commit 9dcdb7b

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

app/(chat)/chat/[id]/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { cookies } from 'next/headers';
32
import { notFound } from 'next/navigation';
43

components/document.tsx

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ import type { SetStateAction } from 'react';
33
import type { UIBlock } from './block';
44
import { FileIcon, LoaderIcon, MessageIcon, PencilEditIcon } from './icons';
55

6-
const getActionText = (type: 'create' | 'update' | 'request-suggestions') => {
6+
const getActionText = (
7+
type: 'create' | 'update' | 'request-suggestions',
8+
tense: 'present' | 'past',
9+
) => {
710
switch (type) {
811
case 'create':
9-
return 'Creating';
12+
return tense === 'present' ? 'Creating' : 'Created';
1013
case 'update':
11-
return 'Updating';
14+
return tense === 'present' ? 'Updating' : 'Updated';
1215
case 'request-suggestions':
13-
return 'Adding suggestions';
16+
return tense === 'present'
17+
? 'Adding suggestions'
18+
: 'Added suggestions to';
1419
default:
1520
return null;
1621
}
@@ -26,7 +31,6 @@ interface DocumentToolResultProps {
2631
export function DocumentToolResult({
2732
type,
2833
result,
29-
block,
3034
setBlock,
3135
}: DocumentToolResultProps) {
3236
return (
@@ -62,8 +66,8 @@ export function DocumentToolResult({
6266
<MessageIcon />
6367
) : null}
6468
</div>
65-
<div className="">
66-
{getActionText(type)} {result.title}
69+
<div className="text-left">
70+
{`${getActionText(type, 'past')} "${result.title}"`}
6771
</div>
6872
</button>
6973
);
@@ -72,11 +76,35 @@ export function DocumentToolResult({
7276
interface DocumentToolCallProps {
7377
type: 'create' | 'update' | 'request-suggestions';
7478
args: { title: string };
79+
setBlock: (value: SetStateAction<UIBlock>) => void;
7580
}
7681

77-
export function DocumentToolCall({ type, args }: DocumentToolCallProps) {
82+
export function DocumentToolCall({
83+
type,
84+
args,
85+
setBlock,
86+
}: DocumentToolCallProps) {
7887
return (
79-
<div className="w-fit border py-2 px-3 rounded-xl flex flex-row items-start justify-between gap-3">
88+
<button
89+
type="button"
90+
className="cursor pointer w-fit border py-2 px-3 rounded-xl flex flex-row items-start justify-between gap-3"
91+
onClick={(event) => {
92+
const rect = event.currentTarget.getBoundingClientRect();
93+
94+
const boundingBox = {
95+
top: rect.top,
96+
left: rect.left,
97+
width: rect.width,
98+
height: rect.height,
99+
};
100+
101+
setBlock((currentBlock) => ({
102+
...currentBlock,
103+
isVisible: true,
104+
boundingBox,
105+
}));
106+
}}
107+
>
80108
<div className="flex flex-row gap-3 items-start">
81109
<div className="text-zinc-500 mt-1">
82110
{type === 'create' ? (
@@ -88,12 +116,12 @@ export function DocumentToolCall({ type, args }: DocumentToolCallProps) {
88116
) : null}
89117
</div>
90118

91-
<div className="">
92-
{getActionText(type)} {args.title}
119+
<div className="text-left">
120+
{`${getActionText(type, 'present')} ${args.title ? `"${args.title}"` : ''}`}
93121
</div>
94122
</div>
95123

96124
<div className="animate-spin mt-1">{<LoaderIcon />}</div>
97-
</div>
125+
</button>
98126
);
99127
}

components/message.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,22 @@ export const PreviewMessage = ({
104104
{toolName === 'getWeather' ? (
105105
<Weather />
106106
) : toolName === 'createDocument' ? (
107-
<DocumentToolCall type="create" args={args} />
107+
<DocumentToolCall
108+
type="create"
109+
args={args}
110+
setBlock={setBlock}
111+
/>
108112
) : toolName === 'updateDocument' ? (
109-
<DocumentToolCall type="update" args={args} />
113+
<DocumentToolCall
114+
type="update"
115+
args={args}
116+
setBlock={setBlock}
117+
/>
110118
) : toolName === 'requestSuggestions' ? (
111119
<DocumentToolCall
112120
type="request-suggestions"
113121
args={args}
122+
setBlock={setBlock}
114123
/>
115124
) : null}
116125
</div>

0 commit comments

Comments
 (0)