@@ -23,6 +23,7 @@ import Image from "next/image";
23
23
import { useCallback , useEffect , useMemo , useState } from "react" ;
24
24
25
25
import type { ChatMessage } from "@/app/api/chat/route" ;
26
+ import { Suggestion , Suggestions } from "@/components/ai-elements/suggestion" ;
26
27
27
28
const MODELS = [
28
29
{
@@ -35,6 +36,12 @@ const MODELS = [
35
36
} ,
36
37
] ;
37
38
39
+ const SUGGESTIONS = [
40
+ "Find top 5 places to visit in Ljubljana, Slovenia" ,
41
+ "Extract top 10 Hacker News articles" ,
42
+ "Get latest NBA scores" ,
43
+ ] ;
44
+
38
45
export default function Home ( ) {
39
46
const [ input , setInput ] = useState ( "" ) ;
40
47
const [ model , setModel ] = useState < string > ( MODELS [ 0 ] . value ) ;
@@ -48,20 +55,20 @@ export default function Home() {
48
55
( e : React . FormEvent ) => {
49
56
e . preventDefault ( ) ;
50
57
if ( input . trim ( ) ) {
51
- sendMessage (
52
- { text : input } ,
53
- {
54
- body : {
55
- model : model ,
56
- } ,
57
- } ,
58
- ) ;
58
+ sendMessage ( { text : input } , { body : { model : model } } ) ;
59
59
setInput ( "" ) ;
60
60
}
61
61
} ,
62
62
[ input , model , sendMessage ] ,
63
63
) ;
64
64
65
+ const handleSuggestionClick = useCallback (
66
+ ( suggestion : string ) => {
67
+ sendMessage ( { text : suggestion } , { body : { model : model } } ) ;
68
+ } ,
69
+ [ sendMessage , model ] ,
70
+ ) ;
71
+
65
72
const liveUrl = useMemo ( ( ) => {
66
73
let url : string | undefined = undefined ;
67
74
@@ -81,6 +88,7 @@ export default function Home() {
81
88
} , [ messages ] ) ;
82
89
83
90
useEffect ( ( ) => {
91
+ // DEBUG
84
92
console . log ( messages ) ;
85
93
} , [ messages ] ) ;
86
94
@@ -160,9 +168,24 @@ export default function Home() {
160
168
</ Conversation >
161
169
162
170
{ /* Input */ }
171
+ { messages . length === 0 && (
172
+ < div className = "flex-none w-full mb-2 border border-transparent" >
173
+ < Suggestions className = "px-2" >
174
+ { SUGGESTIONS . map ( ( suggestion ) => (
175
+ < Suggestion key = { suggestion } onClick = { handleSuggestionClick } suggestion = { suggestion } />
176
+ ) ) }
177
+ </ Suggestions >
178
+ </ div >
179
+ ) }
180
+
163
181
< div className = "flex-none p-2 pt-0" >
164
182
< PromptInput onSubmit = { handleSubmit } >
165
- < PromptInputTextarea onChange = { ( e ) => setInput ( e . target . value ) } value = { input } />
183
+ < PromptInputTextarea
184
+ onChange = { ( e ) => setInput ( e . target . value ) }
185
+ value = { input }
186
+ placeholder = "Automate the web..."
187
+ rows = { 2 }
188
+ />
166
189
< PromptInputToolbar >
167
190
< PromptInputTools >
168
191
< PromptInputModelSelect
0 commit comments