2024-12-03 17:49:38 +03:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { motion } from 'framer-motion';
|
|
|
|
|
import { Button } from './ui/button';
|
|
|
|
|
import { memo } from 'react';
|
2025-05-01 17:47:48 -07:00
|
|
|
import type { UseChatHelpers } from '@ai-sdk/react';
|
|
|
|
|
import type { VisibilityType } from './visibility-selector';
|
2024-12-03 17:49:38 +03:00
|
|
|
|
|
|
|
|
interface SuggestedActionsProps {
|
|
|
|
|
chatId: string;
|
2025-03-20 14:10:45 -07:00
|
|
|
append: UseChatHelpers['append'];
|
2025-05-01 17:47:48 -07:00
|
|
|
selectedVisibilityType: VisibilityType;
|
2024-12-03 17:49:38 +03:00
|
|
|
}
|
|
|
|
|
|
2025-05-01 17:47:48 -07:00
|
|
|
function PureSuggestedActions({
|
|
|
|
|
chatId,
|
|
|
|
|
append,
|
|
|
|
|
selectedVisibilityType,
|
|
|
|
|
}: SuggestedActionsProps) {
|
2024-12-03 17:49:38 +03:00
|
|
|
const suggestedActions = [
|
|
|
|
|
{
|
2024-12-19 17:21:07 +05:30
|
|
|
title: 'What are the advantages',
|
|
|
|
|
label: 'of using Next.js?',
|
|
|
|
|
action: 'What are the advantages of using Next.js?',
|
2024-12-03 17:49:38 +03:00
|
|
|
},
|
|
|
|
|
{
|
2025-01-08 17:52:51 +05:30
|
|
|
title: 'Write code to',
|
|
|
|
|
label: `demonstrate djikstra's algorithm`,
|
|
|
|
|
action: `Write code to demonstrate djikstra's algorithm`,
|
2024-12-03 17:49:38 +03:00
|
|
|
},
|
2024-12-19 17:21:07 +05:30
|
|
|
{
|
|
|
|
|
title: 'Help me write an essay',
|
2024-12-20 23:07:23 +05:30
|
|
|
label: `about silicon valley`,
|
|
|
|
|
action: `Help me write an essay about silicon valley`,
|
2024-12-19 17:21:07 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'What is the weather',
|
|
|
|
|
label: 'in San Francisco?',
|
|
|
|
|
action: 'What is the weather in San Francisco?',
|
|
|
|
|
},
|
2024-12-03 17:49:38 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return (
|
2025-03-04 17:25:46 -08:00
|
|
|
<div
|
|
|
|
|
data-testid="suggested-actions"
|
|
|
|
|
className="grid sm:grid-cols-2 gap-2 w-full"
|
|
|
|
|
>
|
2024-12-03 17:49:38 +03:00
|
|
|
{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}`);
|
|
|
|
|
|
|
|
|
|
append({
|
|
|
|
|
role: 'user',
|
|
|
|
|
content: 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"
|
|
|
|
|
>
|
|
|
|
|
<span className="font-medium">{suggestedAction.title}</span>
|
|
|
|
|
<span className="text-muted-foreground">
|
|
|
|
|
{suggestedAction.label}
|
|
|
|
|
</span>
|
|
|
|
|
</Button>
|
|
|
|
|
</motion.div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-01 17:47:48 -07:00
|
|
|
export const SuggestedActions = memo(
|
|
|
|
|
PureSuggestedActions,
|
|
|
|
|
(prevProps, nextProps) => {
|
|
|
|
|
if (prevProps.chatId !== nextProps.chatId) return false;
|
|
|
|
|
if (prevProps.selectedVisibilityType !== nextProps.selectedVisibilityType)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
);
|