import React, { useState } from 'react'; import Card from "components/ui/card"; import { ArrowUpCircleIcon } from "@heroicons/react/24/solid"; // Define a type for the messages type Message = { sender: 'user' | 'ai'; text: string; }; const AISpeedCoach = () => { // Define the state with an array of Message type const [messages, setMessages] = useState([]); const [input, setInput] = useState(''); const handleSend = () => { if (input.trim() === '') return; // Add user message to the chat setMessages([...messages, { sender: 'user', text: input }]); setInput(''); // Simulate AI response setTimeout(() => { setMessages(prevMessages => [ ...prevMessages, { sender: 'ai', text: 'This is a simulated AI response.' } ]); }, 1000); }; const handleNewChat = () => { // Only clear messages if there are existing messages // console.log(messages.length) // console.log("hellow this is me") if (messages.length > 0) { setMessages([]); } }; return (
{messages.map((message, index) => (
{message.text}
))}
setInput(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && handleSend()} />
); }; export default AISpeedCoach;