pleroma/app/soapbox/features/chats/components/chat.tsx

71 lines
2.2 KiB
TypeScript
Raw Normal View History

import React from 'react';
2022-09-08 07:24:20 -07:00
import RelativeTimestamp from 'soapbox/components/relative-timestamp';
2022-08-18 09:52:04 -07:00
import { Avatar, HStack, Stack, Text } from 'soapbox/components/ui';
import VerificationBadge from 'soapbox/components/verification_badge';
2022-08-18 09:52:04 -07:00
import type { IChat } from 'soapbox/queries/chats';
2022-08-18 09:52:04 -07:00
interface IChatInterface {
chat: IChat,
onClick: (chat: any) => void,
}
2022-08-18 09:52:04 -07:00
const Chat: React.FC<IChatInterface> = ({ chat, onClick }) => {
return (
2022-08-18 09:52:04 -07:00
<button
key={chat.id}
type='button'
onClick={() => onClick(chat)}
2022-08-25 10:44:19 -07:00
className='px-4 py-2 w-full flex flex-col hover:bg-gray-100 dark:hover:bg-gray-800'
2022-09-12 11:42:15 -07:00
data-testid='chat'
2022-08-18 09:52:04 -07:00
>
2022-08-26 09:41:25 -07:00
<HStack alignItems='center' justifyContent='between' space={2} className='w-full'>
2022-08-31 10:04:33 -07:00
<HStack alignItems='center' space={2} className='overflow-hidden'>
<Avatar src={chat.account?.avatar} size={40} className='flex-none' />
2022-08-26 09:41:25 -07:00
2022-08-31 10:04:33 -07:00
<Stack alignItems='start' className='overflow-hidden'>
<div className='flex items-center space-x-1 flex-grow w-full'>
<Text weight='bold' size='sm' align='left' truncate>{chat.account?.display_name || `@${chat.account.username}`}</Text>
2022-08-26 09:41:25 -07:00
{chat.account?.verified && <VerificationBadge />}
</div>
{chat.last_message?.content && (
2022-09-12 11:42:15 -07:00
<Text
align='left'
size='sm'
weight='medium'
theme='muted'
truncate
2022-09-12 11:50:02 -07:00
className='w-full'
2022-09-12 11:42:15 -07:00
data-testid='chat-last-message'
dangerouslySetInnerHTML={{ __html: chat.last_message?.content }}
/>
2022-08-26 09:41:25 -07:00
)}
</Stack>
</HStack>
{chat.last_message && (
<HStack alignItems='center' space={2}>
{chat.last_message.unread && (
2022-09-12 11:42:15 -07:00
<div
className='w-2 h-2 rounded-full bg-secondary-500'
data-testid='chat-unread-indicator'
/>
2022-08-26 09:41:25 -07:00
)}
2022-08-31 10:04:33 -07:00
<RelativeTimestamp
timestamp={chat.last_message.created_at}
align='right'
size='xs'
truncate
/>
2022-08-26 09:41:25 -07:00
</HStack>
)}
2022-08-18 09:52:04 -07:00
</HStack>
</button>
);
};
export default Chat;