2024-12-03 17:49:38 +03:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { motion } from 'framer-motion';
|
|
|
|
|
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';
|
2025-07-03 02:26:34 -07:00
|
|
|
import type { ChatMessage } from '@/lib/types';
|
2025-08-28 14:15:36 +01:00
|
|
|
import { Suggestion } from './elements/suggestion';
|
2024-12-03 17:49:38 +03:00
|
|
|
|
|
|
|
|
interface SuggestedActionsProps {
|
|
|
|
|
chatId: string;
|
2025-07-03 02:26:34 -07:00
|
|
|
sendMessage: UseChatHelpers<ChatMessage>['sendMessage'];
|
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,
|
2025-07-03 02:26:34 -07:00
|
|
|
sendMessage,
|
2025-05-01 17:47:48 -07:00
|
|
|
selectedVisibilityType,
|
|
|
|
|
}: SuggestedActionsProps) {
|
2024-12-03 17:49:38 +03:00
|
|
|
const suggestedActions = [
|
2025-08-28 14:15:36 +01:00
|
|
|
'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?',
|
2024-12-03 17:49:38 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return (
|
2025-08-28 14:15:36 +01:00
|
|
|
<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}
|
2024-12-03 17:49:38 +03:00
|
|
|
>
|
2025-08-28 14:15:36 +01:00
|
|
|
<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>
|
|
|
|
|
))}
|
2024-12-03 17:49:38 +03:00
|
|
|
</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;
|
|
|
|
|
},
|
|
|
|
|
);
|