mirror of
https://github.com/aljazceru/goose.git
synced 2026-01-07 00:14:23 +01:00
59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
import React, { useRef, useMemo } from 'react';
|
|
import LinkPreview from './LinkPreview';
|
|
import { extractUrls } from '../utils/urlUtils';
|
|
import MarkdownContent from './MarkdownContent';
|
|
import { Message, getTextContent } from '../types/message';
|
|
import MessageCopyLink from './MessageCopyLink';
|
|
import { formatMessageTimestamp } from '../utils/timeUtils';
|
|
|
|
interface UserMessageProps {
|
|
message: Message;
|
|
}
|
|
|
|
export default function UserMessage({ message }: UserMessageProps) {
|
|
const contentRef = useRef<HTMLDivElement>(null);
|
|
|
|
// Extract text content from the message
|
|
const textContent = getTextContent(message);
|
|
|
|
// Memoize the timestamp
|
|
const timestamp = useMemo(() => formatMessageTimestamp(message.created), [message.created]);
|
|
|
|
// Extract URLs which explicitly contain the http:// or https:// protocol
|
|
const urls = extractUrls(textContent, []);
|
|
|
|
return (
|
|
<div className="flex justify-end mt-[16px] w-full opacity-0 animate-[appear_150ms_ease-in_forwards]">
|
|
<div className="flex-col max-w-[85%]">
|
|
<div className="flex flex-col group">
|
|
<div className="flex bg-slate text-white rounded-xl rounded-br-none py-2 px-3">
|
|
<div ref={contentRef}>
|
|
<MarkdownContent
|
|
content={textContent}
|
|
className="text-white prose-a:text-white user-message"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div className="relative h-[22px] flex justify-end">
|
|
<div className="absolute right-0 text-xs text-textSubtle pt-1 transition-all duration-200 group-hover:-translate-y-4 group-hover:opacity-0">
|
|
{timestamp}
|
|
</div>
|
|
<div className="absolute right-0 pt-1">
|
|
<MessageCopyLink text={textContent} contentRef={contentRef} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* TODO(alexhancock): Re-enable link previews once styled well again */}
|
|
{false && urls.length > 0 && (
|
|
<div className="flex flex-wrap mt-2">
|
|
{urls.map((url, index) => (
|
|
<LinkPreview key={index} url={url} />
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|