Skip to content

Commit af6cd56

Browse files
committed
fix: use public v2 API, add Escape key support, extract shared GridIcon
Replace internal useCopilotChatInternal hook with public useAgent + useCopilotKit from @copilotkit/react-core/v2. Add Escape key handler to close the demo gallery drawer. Extract duplicated grid SVG into a shared GridIcon component.
1 parent 8e03be2 commit af6cd56

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

apps/app/src/app/page.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ import { ExampleLayout } from "@/components/example-layout";
55
import { useGenerativeUIExamples, useExampleSuggestions } from "@/hooks";
66
import { ExplainerCardsPortal } from "@/components/explainer-cards";
77
import { DemoGallery, type DemoItem } from "@/components/demo-gallery";
8-
import { CopilotChat } from "@copilotkit/react-core/v2";
9-
import { useCopilotChatInternal } from "@copilotkit/react-core";
8+
import { GridIcon } from "@/components/demo-gallery/grid-icon";
9+
import { CopilotChat, useAgent, useCopilotKit } from "@copilotkit/react-core/v2";
1010

1111
export default function HomePage() {
1212
useGenerativeUIExamples();
1313
useExampleSuggestions();
1414

1515
const [demoDrawerOpen, setDemoDrawerOpen] = useState(false);
16-
const { sendMessage } = useCopilotChatInternal();
16+
const { agent } = useAgent();
17+
const { copilotkit } = useCopilotKit();
1718

1819
const handleTryDemo = (demo: DemoItem) => {
1920
setDemoDrawerOpen(false);
20-
sendMessage({ id: crypto.randomUUID(), content: demo.prompt, role: "user" });
21+
agent.addMessage({ id: crypto.randomUUID(), content: demo.prompt, role: "user" });
22+
copilotkit.runAgent({ agent });
2123
};
2224

2325
// Widget bridge: handle messages from widget iframes
@@ -76,12 +78,7 @@ export default function HomePage() {
7678
}}
7779
title="Open Demo Gallery"
7880
>
79-
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
80-
<rect width="7" height="7" x="3" y="3" rx="1" />
81-
<rect width="7" height="7" x="14" y="3" rx="1" />
82-
<rect width="7" height="7" x="14" y="14" rx="1" />
83-
<rect width="7" height="7" x="3" y="14" rx="1" />
84-
</svg>
81+
<GridIcon size={15} />
8582
Demos
8683
</button>
8784
<a
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { CSSProperties } from "react";
2+
3+
interface GridIconProps {
4+
size?: number;
5+
style?: CSSProperties;
6+
}
7+
8+
export function GridIcon({ size = 18, style }: GridIconProps) {
9+
return (
10+
<svg
11+
width={size}
12+
height={size}
13+
viewBox="0 0 24 24"
14+
fill="none"
15+
stroke="currentColor"
16+
strokeWidth="2"
17+
strokeLinecap="round"
18+
strokeLinejoin="round"
19+
style={style}
20+
>
21+
<rect width="7" height="7" x="3" y="3" rx="1" />
22+
<rect width="7" height="7" x="14" y="3" rx="1" />
23+
<rect width="7" height="7" x="14" y="14" rx="1" />
24+
<rect width="7" height="7" x="3" y="14" rx="1" />
25+
</svg>
26+
);
27+
}

apps/app/src/components/demo-gallery/index.tsx

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"use client";
22

3-
import { useState } from "react";
3+
import { useState, useEffect } from "react";
44
import { DEMO_EXAMPLES, type DemoCategory, type DemoItem } from "./demo-data";
55
import { DemoCard } from "./demo-card";
66
import { CategoryFilter } from "./category-filter";
7+
import { GridIcon } from "./grid-icon";
78

89
export type { DemoItem } from "./demo-data";
910

@@ -21,6 +22,15 @@ export function DemoGallery({ open, onClose, onTryDemo }: DemoGalleryProps) {
2122
? DEMO_EXAMPLES.filter((d) => d.category === selectedCategory)
2223
: DEMO_EXAMPLES;
2324

25+
useEffect(() => {
26+
if (!open) return;
27+
const handleKeyDown = (e: KeyboardEvent) => {
28+
if (e.key === "Escape") onClose();
29+
};
30+
document.addEventListener("keydown", handleKeyDown);
31+
return () => document.removeEventListener("keydown", handleKeyDown);
32+
}, [open, onClose]);
33+
2434
return (
2535
<>
2636
{/* Backdrop */}
@@ -53,22 +63,7 @@ export function DemoGallery({ open, onClose, onTryDemo }: DemoGalleryProps) {
5363
}}
5464
>
5565
<div className="flex items-center gap-2">
56-
<svg
57-
width="18"
58-
height="18"
59-
viewBox="0 0 24 24"
60-
fill="none"
61-
stroke="currentColor"
62-
strokeWidth="2"
63-
strokeLinecap="round"
64-
strokeLinejoin="round"
65-
style={{ color: "var(--text-secondary, #666)" }}
66-
>
67-
<rect width="7" height="7" x="3" y="3" rx="1" />
68-
<rect width="7" height="7" x="14" y="3" rx="1" />
69-
<rect width="7" height="7" x="14" y="14" rx="1" />
70-
<rect width="7" height="7" x="3" y="14" rx="1" />
71-
</svg>
66+
<GridIcon size={18} style={{ color: "var(--text-secondary, #666)" }} />
7267
<h2
7368
className="text-base font-semibold"
7469
style={{ color: "var(--text-primary, #1a1a1a)" }}

0 commit comments

Comments
 (0)