feat: ai elements (#1143)
This commit is contained in:
parent
66e8227655
commit
f09be3f286
38 changed files with 3558 additions and 500 deletions
|
|
@ -1,11 +1,11 @@
|
|||
'use client';
|
||||
|
||||
import { motion } from 'framer-motion';
|
||||
import { Button } from './ui/button';
|
||||
import { memo } from 'react';
|
||||
import type { UseChatHelpers } from '@ai-sdk/react';
|
||||
import type { VisibilityType } from './visibility-selector';
|
||||
import type { ChatMessage } from '@/lib/types';
|
||||
import { Suggestion } from './elements/suggestion';
|
||||
|
||||
interface SuggestedActionsProps {
|
||||
chatId: string;
|
||||
|
|
@ -19,61 +19,37 @@ function PureSuggestedActions({
|
|||
selectedVisibilityType,
|
||||
}: SuggestedActionsProps) {
|
||||
const suggestedActions = [
|
||||
{
|
||||
title: 'What are the advantages',
|
||||
label: 'of using Next.js?',
|
||||
action: 'What are the advantages of using Next.js?',
|
||||
},
|
||||
{
|
||||
title: 'Write code to',
|
||||
label: `demonstrate djikstra's algorithm`,
|
||||
action: `Write code to demonstrate djikstra's algorithm`,
|
||||
},
|
||||
{
|
||||
title: 'Help me write an essay',
|
||||
label: `about silicon valley`,
|
||||
action: `Help me write an essay about silicon valley`,
|
||||
},
|
||||
{
|
||||
title: 'What is the weather',
|
||||
label: 'in San Francisco?',
|
||||
action: 'What is the weather in San Francisco?',
|
||||
},
|
||||
'What are the advantages of using Next.js?',
|
||||
'Write code to demonstrate Dijkstra\'s algorithm',
|
||||
'Help me write an essay about Silicon Valley',
|
||||
'What is the weather in San Francisco?',
|
||||
];
|
||||
|
||||
return (
|
||||
<div
|
||||
data-testid="suggested-actions"
|
||||
className="grid sm:grid-cols-2 gap-2 w-full"
|
||||
>
|
||||
{suggestedActions.map((suggestedAction, index) => (
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0, y: 20 }}
|
||||
transition={{ delay: 0.05 * index }}
|
||||
key={`suggested-action-${suggestedAction.title}-${index}`}
|
||||
className={index > 1 ? 'hidden sm:block' : 'block'}
|
||||
>
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={async () => {
|
||||
window.history.replaceState({}, '', `/chat/${chatId}`);
|
||||
|
||||
sendMessage({
|
||||
role: 'user',
|
||||
parts: [{ type: 'text', text: suggestedAction.action }],
|
||||
});
|
||||
}}
|
||||
className="text-left border rounded-xl px-4 py-3.5 text-sm flex-1 gap-1 sm:flex-col w-full h-auto justify-start items-start"
|
||||
<div data-testid="suggested-actions" className="grid sm:grid-cols-2 gap-2 w-full">
|
||||
{suggestedActions.map((suggestedAction, index) => (
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0, y: 20 }}
|
||||
transition={{ delay: 0.05 * index }}
|
||||
key={suggestedAction}
|
||||
>
|
||||
<span className="font-medium">{suggestedAction.title}</span>
|
||||
<span className="text-muted-foreground">
|
||||
{suggestedAction.label}
|
||||
</span>
|
||||
</Button>
|
||||
</motion.div>
|
||||
))}
|
||||
<Suggestion
|
||||
suggestion={suggestedAction}
|
||||
onClick={(suggestion) => {
|
||||
window.history.replaceState({}, '', `/chat/${chatId}`);
|
||||
sendMessage({
|
||||
role: 'user',
|
||||
parts: [{ type: 'text', text: suggestion }],
|
||||
});
|
||||
}}
|
||||
className="text-left w-full h-auto whitespace-normal p-3"
|
||||
>
|
||||
{suggestedAction}
|
||||
</Suggestion>
|
||||
</motion.div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue