Spaces:
Build error
Build error
Upload components/ChatMessage.js with huggingface_hub
Browse files- components/ChatMessage.js +32 -0
components/ChatMessage.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function ChatMessage({ message, isUser }) {
|
| 2 |
+
const formatTime = (timestamp) => {
|
| 3 |
+
return new Date(timestamp).toLocaleTimeString('en-US', {
|
| 4 |
+
hour: '2-digit',
|
| 5 |
+
minute: '2-digit'
|
| 6 |
+
});
|
| 7 |
+
};
|
| 8 |
+
|
| 9 |
+
return (
|
| 10 |
+
<div className={`flex mb-4 ${isUser ? 'justify-end' : 'justify-start'}`}>
|
| 11 |
+
<div className={`flex items-start space-x-2 max-w-[80%] ${isUser ? 'flex-row-reverse space-x-reverse' : ''}`}>
|
| 12 |
+
<div className={`w-8 h-8 rounded-full flex items-center justify-center text-white text-sm font-medium ${
|
| 13 |
+
isUser ? 'bg-primary-500' : 'bg-secondary-500'
|
| 14 |
+
}`}>
|
| 15 |
+
{isUser ? 'You' : 'AI'}
|
| 16 |
+
</div>
|
| 17 |
+
<div>
|
| 18 |
+
<div className={`message-bubble ${
|
| 19 |
+
isUser ? 'user-message' : 'bot-message'
|
| 20 |
+
}`}>
|
| 21 |
+
<p className="text-sm leading-relaxed whitespace-pre-wrap">{message.content}</p>
|
| 22 |
+
</div>
|
| 23 |
+
<div className={`text-xs text-gray-500 mt-1 ${
|
| 24 |
+
isUser ? 'text-right' : 'text-left'
|
| 25 |
+
}`}>
|
| 26 |
+
{formatTime(message.timestamp)}
|
| 27 |
+
</div>
|
| 28 |
+
</div>
|
| 29 |
+
</div>
|
| 30 |
+
</div>
|
| 31 |
+
);
|
| 32 |
+
}
|