Skip to content

Commit 5a8a704

Browse files
committed
fix: use v2 sendMessage API for demo gallery prompts
Replace deprecated appendMessage/useCopilotChat with sendMessage/useCopilotChatInternal to fix "isResultMessage is not a function" error when clicking demo cards.
1 parent 501f83c commit 5a8a704

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

apps/app/src/app/page.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
"use client";
22

3-
import { useEffect } from "react";
3+
import { useEffect, useState } from "react";
44
import { ExampleLayout } from "@/components/example-layout";
55
import { useGenerativeUIExamples, useExampleSuggestions } from "@/hooks";
66
import { ExplainerCardsPortal } from "@/components/explainer-cards";
7+
import { DemoGallery, type DemoItem } from "@/components/demo-gallery";
78
import { CopilotChat } from "@copilotkit/react-core/v2";
9+
import { useCopilotChatInternal } from "@copilotkit/react-core";
810

911
export default function HomePage() {
1012
useGenerativeUIExamples();
1113
useExampleSuggestions();
1214

15+
const [demoDrawerOpen, setDemoDrawerOpen] = useState(false);
16+
const { sendMessage } = useCopilotChatInternal();
17+
18+
const handleTryDemo = (demo: DemoItem) => {
19+
setDemoDrawerOpen(false);
20+
sendMessage({ id: crypto.randomUUID(), content: demo.prompt, role: "user" });
21+
};
22+
1323
// Widget bridge: handle messages from widget iframes
1424
useEffect(() => {
1525
const handler = (e: MessageEvent) => {
@@ -55,6 +65,25 @@ export default function HomePage() {
5565
</p>
5666
</div>
5767
<div className="flex items-center gap-2">
68+
<button
69+
onClick={() => setDemoDrawerOpen(true)}
70+
className="inline-flex items-center gap-1.5 px-3 py-2 rounded-full text-sm font-medium no-underline whitespace-nowrap transition-all duration-150 hover:-translate-y-px cursor-pointer"
71+
style={{
72+
color: "var(--text-secondary)",
73+
border: "1px solid var(--color-border-glass, rgba(0,0,0,0.1))",
74+
background: "var(--surface-primary, rgba(255,255,255,0.6))",
75+
fontFamily: "var(--font-family)",
76+
}}
77+
title="Open Demo Gallery"
78+
>
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>
85+
Demos
86+
</button>
5887
<a
5988
href="https://github.com/CopilotKit/OpenGenerativeUI"
6089
target="_blank"
@@ -84,6 +113,11 @@ export default function HomePage() {
84113
</div>
85114
</div>
86115

116+
<DemoGallery
117+
open={demoDrawerOpen}
118+
onClose={() => setDemoDrawerOpen(false)}
119+
onTryDemo={handleTryDemo}
120+
/>
87121
</>
88122
);
89123
}

0 commit comments

Comments
 (0)